java-Google视觉API从文件加载凭据

创建注释器客户端时,我想使用其他凭证文件.我目前可以使用transalte API做到这一点,如下所示:

 Credentials creds = ServiceAccountCredentials.fromStream(new FileInputStream("path/to/credentials.json"));
 return TranslateOptions.newBuilder().setCredentials(creds).build().getService();  

是否有使用ImageAnnotatorClient进行操作的等效方法?

编辑:我正在使用谷歌云的Java SDK版本:1.16.0

解决方法:

ServiceAccountCredentials-> FixedCredentialsProvider-> ImageAnnotatorSettings.Builder-> ImageAnnotatorSettings-> ImageAnnotatorClient

示例(从文档复制):

Credentials myCredentials = ServiceAccountCredentials.fromStream(
    new FileInputStream("path/to/credentials.json"));

ImageAnnotatorSettings imageAnnotatorSettings =
    ImageAnnotatorSettings.newBuilder()
    .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
    .build();

ImageAnnotatorClient imageAnnotatorClient =
    ImageAnnotatorClient.create(imageAnnotatorSettings);

用于此的文档(仍然)令人惊讶地令人沮丧,无法找到和导航.它们之间无法始终保持链接,周围有多个版本,URL更改的频率比他们应有的频繁,并且许多Google自己的链接返回404.

> ImageAnnotatorClient:com.google.cloud.vision.v1.ImageAnnotatorClient

上一篇:centos7安装rabbitmq并简单使用


下一篇:获取jenkins插件最新版本