【发布时间】:2021-09-26 20:49:09
【问题描述】:
使用 Google Translate V3 API 验证服务帐户的默认方式是通过环境变量。这个名为 GOOGLE_APPLICATION_CREDENTIALS 的 env var 指向一个带有凭证的 json 文件,如下所述: https://cloud.google.com/docs/authentication/production
但是,在其他位置使用文件时,如何使用所需的凭据?我可以从 FileStream 创建凭据对象,如 google 文档中所述。但是,使用此凭证对象仅适用于谷歌云存储。 TranslateTextRequest 的构建器不接受这样的凭证对象。 https://googleapis.dev/dotnet/Google.Cloud.Translate.V3/2.0.0/api/Google.Cloud.Translate.V3.TranslateTextRequest.html
唯一的解决方法是将文件复制到环境变量中指定的位置,但这看起来很奇怪,并且在未设置该变量时会失败。
【问题讨论】:
-
您使用哪种语言/SDK?从文档。链接似乎是.NET,但我不确定。
-
使用 TranslationServiceClientBuilder 并指定 JsonCredentials googleapis.dev/dotnet/Google.Cloud.Translate.V3/2.0.0/api/…
-
@Iñigo 抱歉,我应该指定这是用 Java 编写的。
-
@JohnHanley 非常感谢。这看起来像我要找的东西。
-
John Hanley 的建议是否解决了您的问题?你已经尝试过了吗?你有什么错误吗?
标签: authentication google-cloud-platform google-translation-api