我一直试图通过java程序调用视频智能的其余API来注释本地文件。这是我的代码:
byte[] data = Files.readAllBytes(path);
byte[] encodedBytes = Base64.encodeBase64(data);
URIBuilder builder = new URIBuilder("https://videointelligence.googleapis.com/v1beta2/videos:annotate");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "application/json");
request.setHeader("X-Goog-Api-Key",MyKey);
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
jsonArray.put("LABEL_DETECTION");
json.put("inputContent", encodedBytes);
json.put("features", jsonArray);
StringEntity reqEntity = new StringEntity(json.toString());
request.setEntity(reqEntity);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
我收到此错误: "错误":{ "代码":400, " message":"收到无效的JSON有效负载。未知名称\" input_content \&#34 ;: Proto字段不重复,无法启动列表。
有人可以帮我解决这个错误吗?谢谢
答案 0 :(得分:0)
错误消息实际上没有帮助。这里的问题是“inputContent”应该是String
而不是byte[]
。这对我有用:
String str = new String(encodedBytes, "UTF-8");
requestJson.put("inputContent", str);