首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用json作为身份验证来创建TranslationServiceClient?

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

Stack Overflow用户
提问于 2020-07-07 22:14:55
回答 1查看 1.6K关注 0票数 2

你好,谢谢你阅读我的问题。

我正在努力将一些代码从Google.Cloud.Translation.V2转换为Google.Cloud.Translate.V3,因为我们需要使用api高级特性。我们使用TranslationClient来获取翻译(来自V2库),但是我们需要使用TranslationServiceClient (来自V3库)。我很难用我们的凭据实例化TranslationServiceClient。在V2中实现它的方法很简单:

代码语言:javascript
运行
复制
TranslationClient.Create(GoogleCredential.FromJson("{\"the credentials\"}"));

从阅读文档可以清楚地看到,要创建一个没有默认设置的TranslationServiceClient,您需要使用TranslationServiceClientBuilder并提供凭证。我找不到任何例子,所有的代码片段都使用TranslationServiceClient.Create(),它不允许任何参数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-08 15:35:56

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

代码语言:javascript
运行
复制
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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62784724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档