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

How does one create a TranslationServiceClient using a json as authentication?

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

我正在努力将一些代码从 Google.Cloud.Translation.V2 过渡到 Google.Cloud.Translate.V3,因为我们需要使用 api 高级功能。 我们正在使用 TranslationClient 来获取翻译(来自 V2 库),但我们需要改用 TranslationServiceClient (来自 V3 库。) 我在使用我们的凭据实例化 TranslationServiceClient 时遇到问题。在 V2 中实现的方法很简单:

TranslationClient.Create(GoogleCredential.FromJson("{\"the credentials\"}"));

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

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

TranslationServiceClient client = new TranslationServiceClientBuilder {
                        JsonCredentials = "{\"the credentials\"}"
                    }.Build()

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