我想在创建 Annotator 客户端时使用不同的凭据文件。我目前可以像这样使用 transalte API 来做到这一点:
Credentials creds = ServiceAccountCredentials.fromStream(new FileInputStream("path/to/credentials.json"));
return TranslateOptions.newBuilder().setCredentials(creds).build().getService();
ImageAnnotatorClient
是否有等效的方法?
编辑:我正在使用 google cloud java sdk 版本:1.16.0
最佳答案
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);
- ImageAnnotatorClient:
com.google.cloud.vision.v1.ImageAnnotatorClient
🔗 - ImageAnnotatorSettings:
com.google.cloud.vision.v1.ImageAnnotatorSettings
🔗 - ClientSettings.Builder:
com.google.api.gax.rpc.ClientSettings.Builder
🔗 - FixedCredentialsProvider:
com.google.api.gax.core.FixedCredentialsProvider
🔗 - ServiceAccountCredentials:
com.google.auth.oauth2.ServiceAccountCredentials
🔗
注意:以上是针对 Java 的。 API for C#是不同的。
关于java - Google vision API 从文件加载凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48850479/