vb.net - google.cloud.translation.v2,如何指定API键?
vb.net - google.cloud.translation.v2, how to specify API key?
我正在尝试使用 google.cloud.translation.v2
API(特别是 V2,因为我读到 V3 不支持 API 密钥,但仅支持服务帐户)但我不能够找到如何指定我的 API 密钥。
到目前为止我的代码是这样的,当我 运行 它时,我收到 Google 的错误消息,它需要身份验证..
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
我正在尝试使用 google.cloud.translation.v2
API(特别是 V2,因为我读到 V3 不支持 API 密钥,但仅支持服务帐户)但我不能够找到如何指定我的 API 密钥。
到目前为止我的代码是这样的,当我 运行 它时,我收到 Google 的错误消息,它需要身份验证..
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