如何为请求Vision.Images.Annotate设置超时

时间:2017-07-04 15:47:48

标签: java google-apis-explorer

我使用下面的代码来调用google cloud vision api。如果我没有在设定的超时内得到响应,我怎么能找不到请求的响应超时。

Vision.Images.Annotate annotateRequest =
                vision.images().annotate(batchAnnotateImagesRequest);
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotateRequest.setDisableGZipContent(true);
Log.d(TAG, "created Cloud Vision request object, sending request");

BatchAnnotateImagesResponse response = annotateRequest.execute();

1 个答案:

答案 0 :(得分:0)

您可以使用ImageAnnotatorSettings.Builder设置超时值

    final ImageAnnotatorSettings.Builder imageAnnotatorSettingsBuilder =
            ImageAnnotatorSettings.newBuilder();
    imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettings().toBuilder()
            .setTotalTimeout(org.threeten.bp.Duration.ofSeconds(45))
            .setMaxAttempts(1);
final ImageAnnotatorSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build();
    ImageAnnotatorClient vision = ImageAnnotatorClient.create(imageAnnotatorSettings)