我试图使用google.cloud.translation.v2
API,(特别是V2,因为我已经读到V3不支持API密钥,但只支持服务帐户),我无法找到如何指定我的API密钥。
到目前为止,我的代码是这样的,当我运行它时,我得到谷歌的错误消息,它需要身份验证..
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim client As TranslationClient = TranslationClient.Create()
Dim result As TranslationResult = client.TranslateText(TextBox4.Text, LanguageCodes.English, LanguageCodes.German, TranslationModel.Base)
TextBox5.Text = result.TranslatedText
End Sub
我已经搜索了几个小时,但无法找到如何指定API密钥。
我终于找到了我的问题的答案:
Dim service As New TranslateService(New BaseClientService.Initializer With {.ApiKey = "AIzaxxxxxxxxxxxxxxxxxxxxx-xxxxmI"})
Dim client As New TranslationClientImpl(service)
Dim result As TranslationResult = client.TranslateText(TextBox4.Text, LanguageCodes.English)
TextBox5.Text = result.TranslatedText