0

我一直在尝试通过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,“消息”:“收到无效的 JSON 有效负载。未知名称\“输入内容\”:原始字段不重复,无法启动列表。

有人可以帮我解决这个错误吗?谢谢你

4

1 回答 1

0

错误消息并没有真正的帮助。这里的问题是“inputContent”应该String代替byte[]. 这对我有用:

String str = new String(encodedBytes, "UTF-8");
requestJson.put("inputContent", str);
于 2018-06-17T11:12:48.390 回答