【问题标题】:vb.net - google.cloud.translation.v2, how to specify API key?vb.net - google.cloud.translation.v2,如何指定 API 密钥?
【发布时间】:2021-10-01 05:45:09
【问题描述】:

我正在尝试使用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 密钥。

【问题讨论】:

    标签: vb.net google-cloud-platform google-translate api-key


    【解决方案1】:

    终于找到了我的问题的答案:

        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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      • 2020-04-15
      相关资源
      最近更新 更多