在 JAVA 中调用其余视频情报 API

Calling the rest video intelligence API in JAVA

我一直在尝试通过 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();

我收到此错误: "error":{ "code": 400, "message": "Invalid JSON payload received. Unknown name \"input_content\": Proto 字段不重复,无法开始列表。

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

错误消息并没有多大帮助。这里的问题是 "inputContent" 应该是 String 而不是 byte[]。这对我有用:

String str = new String(encodedBytes, "UTF-8");
requestJson.put("inputContent", str);