gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:23:03 26 4
gpt4 key购买 nike

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

我正在努力将一些代码从 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

关于c# - 如何使用 json 作为身份验证创建 TranslationServiceClient?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62784724/

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