gpt4 book ai didi

java - Google vision API 从文件加载凭证

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:01 24 4
gpt4 key购买 nike

我想在创建 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

最佳答案

凭据 🔗 -> CredentialsProvider 🔗

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com