ImageAnnotatorSettings

ImageAnnotatorSettings

我正在使用下面的代码来调用谷歌云视觉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();

最佳答案

您可以使用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)

08-27 02:31