请求的身份验证凭据无效。云语音API中预期的OAuth 2访问令牌错误

问题描述 投票:13回答:3

我已经按照谷歌云语音api快速启动请求api使用

curl -s -H "Content-Type: application/json" \
     -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
     https://speech.googleapis.com/v1/speech:recognize \
     -d @sync-request.json

并跟随 link,但我得到了错误

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

我现在应该怎么做?

提前致谢

api oauth google-cloud-platform google-speech-api
3个回答
10
投票

可能是“应用程序默认凭据”不可用

尝试通过运行登录

gcloud auth application-default login

并按照说明,参考:gcloud auth application-default login

如果要确保身份验证过程顺利进行,请运行:

gcloud auth application-default print-access-token

你应该看到一个访问令牌,参考gcloud auth application-default print-access-token


7
投票

$(gcloud auth application-default print-access-token)替换为调用命令时打印的内容。


4
投票

我通过注销修复了问题,并登录以同意google自上次使用谷歌云(我的情况下是firebase)以来所做的一些新条款和条件。

© www.soinside.com 2019 - 2024. All rights reserved.