如何使用 json 作为身份验证创建 TranslationServiceClient?

Bea*_*ase 2 c# google-translate google-cloud-platform

您好,感谢您阅读我的问题。

我正在努力将一些代码从 转换Google.Cloud.Translation.V2Google.Cloud.Translate.V3,因为我们需要利用 api 高级功能。我们正在使用 aTranslationClient来获取翻译(来自 V2 库),但我们需要使用(TranslationServiceClient来自 V3 库)。我在TranslationServiceClient使用我们的凭据实例化 a 时遇到问题。在 V2 中执行此操作的方法很简单:

TranslationClient.Create(GoogleCredential.FromJson("{\"the credentials\"}"));
Run Code Online (Sandbox Code Playgroud)

通过阅读文档,我清楚地知道,要创建一个TranslationServiceClient没有默认设置的文件,您需要使用 aTranslationServiceClientBuilder并提供凭据。我找不到任何示例,所有代码片段都使用TranslationServiceClient.Create()不允许任何参数的方法。

Bea*_*ase 6

由于目标是TranslationServiceClient使用 json 作为身份验证创建一个,因此一种方法如下:

TranslationServiceClient client = new TranslationServiceClientBuilder {
                        JsonCredentials = "{\"the credentials\"}"
                    }.Build()
Run Code Online (Sandbox Code Playgroud)

更多信息请访问https://cloud.google.com/docs/authentication/development#passing_the_path_to_the_service_account_key_in_code

  • 我如何将 API 密钥提供给那个野兽? (2认同)