moh*_*317 1 c# google-translate google-cloud-storage
我正在尝试在.net项目中使用Google Translator API。我已经安装了这个库
安装套件Google.Cloud.Storage.V1
在我的代码中,我正在尝试
Console.OutputEncoding = System.Text.Encoding.Unicode;
TranslationClient client = TranslationClient.Create();
var response = client.TranslateText("Hello World.", "ru");
Console.WriteLine(response.TranslatedText);
Run Code Online (Sandbox Code Playgroud)
我收到验证错误,我真的很困惑该怎么做。我不能按原样将api密钥传递给create函数吗?还是一个问题?
我看到Create函数有一个选项
GoogleCredential.FromJson(parmas)
Run Code Online (Sandbox Code Playgroud)
但是我可以在其中传递一个json字符串吗?如果是的话,该JSON的格式应该是什么?
提前致谢。
以下是示例应用程序:https :
//github.com/GoogleCloudPlatform/dotnet-docs-samples
身份验证信息:
https : //cloud.google.com/docs/authentication/
https://cloud.google.com/docs/authentication/api-keys
首先安装NuGet软件包:
PM> install-package Google.Cloud.Translation.V2 -pre
这是为我工作的绝对最简单的代码。3行代码,还不错:)
var service = new TranslateService(new BaseClientService.Initializer { ApiKey = apiKeyTranslate });
var client = new TranslationClientImpl(service, TranslationModel.ServiceDefault);
var result = client.TranslateText("Hello, World", "sr");
Response.Write(result.TranslatedText);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2197 次 |
最近记录: |