Google cloud platform 谷歌云翻译API问题

Google cloud platform 谷歌云翻译API问题,google-cloud-platform,google-api,google-translation-api,Google Cloud Platform,Google Api,Google Translation Api,我是堆栈溢出的新手。如果我在这里做了任何违反规则的事,请原谅 我正在尝试使用谷歌云翻译API,我完全遵循了本文中描述的步骤 当我运行curl命令时,响应表明我没有有效的API密钥。请看下面我收到的确切答复 { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The req

我是堆栈溢出的新手。如果我在这里做了任何违反规则的事,请原谅

我正在尝试使用谷歌云翻译API,我完全遵循了本文中描述的步骤

当我运行curl命令时,响应表明我没有有效的API密钥。请看下面我收到的确切答复

{

  "error": {

    "code": 403,

    "message": "The request is missing a valid API key.",

    "errors": [

      {

        "message": "The request is missing a valid API key.",

        "domain": "global",

        "reason": "forbidden"

      }

    ],

    "status": "PERMISSION_DENIED"

  }

}
我再次查看了链接,但我相信链接中的任何步骤都没有提到API密钥。该链接提到了服务帐户密钥。我在环境变量上正确设置了服务帐户私钥的路径,并且没有关于它的错误报告

有人能帮我设置API密钥吗

提前谢谢

环境:
Win Powershell 5.1.18362.752

以下文档建议使用服务帐户通过翻译API进行身份验证。为此,您需要遵循以下步骤:

  • 为您的项目启用云翻译API,以及
  • 。这可能会导致问题,因为如果未设置,请求可能正在搜索API密钥,即不同的身份验证方法
  • 设置JSON凭据文件后,请重试curl命令
我已经测试过了,效果很好

curl -s -X POST -H "Content-Type: application/json"     -H "Authorization: Bearer "$(gcloud auth application-default print-access-token)     --data "{                       
  'q': 'The Great Pyramid of Giza (also known as the Pyramid of Khufu or the
        Pyramid of Cheops) is the oldest and largest of the three pyramids in
        the Giza pyramid complex.',
  'source': 'en',
  'target': 'es',
  'format': 'text'
}" "https://translation.googleapis.com/language/translate/v2"
另一方面,可以在请求中使用API键,如图所示,但它需要事先生成API键

curl -s -X POST -H "Content-Type: application/json" \ \
    --data "{
  'q': 'The Great Pyramid of Giza (also known as the Pyramid of Khufu or the
        Pyramid of Cheops) is the oldest and largest of the three pyramids in
        the Giza pyramid complex.',
  'source': 'en',
  'target': 'es',
  'format': 'text'
}" "https://translation.googleapis.com/language/translate/v2?key=XXXXXXXXXXXXXXXXXXXXXXXXXX"