Bea*_*ase 2 c# google-translate google-cloud-platform
您好,感谢您阅读我的问题。
我正在努力将一些代码从 转换Google.Cloud.Translation.V2
为Google.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()
不允许任何参数的方法。
由于目标是TranslationServiceClient
使用 json 作为身份验证创建一个,因此一种方法如下:
TranslationServiceClient client = new TranslationServiceClientBuilder {
JsonCredentials = "{\"the credentials\"}"
}.Build()
Run Code Online (Sandbox Code Playgroud)