【问题标题】:Google Cloud Text to Speech INVALID API KEYGoogle Cloud Text to Speech 无效的 API 密钥
【发布时间】:2019-03-15 20:47:09
【问题描述】:

我关注了这个页面:

https://cloud.google.com/text-to-speech/docs/quickstart-protocol

我生成了一个访问令牌:

gcloud auth application-default print-access-token

输入后:

curl -H "Authorization: Bearer "$(my_token_is_in_here) \
  -H "Content-Type: application/json; charset=utf-8" \
  --data "{
    'input':{
      'text':'Android is a mobile operating system developed by Google,
         based on the Linux kernel and designed primarily for
         touchscreen mobile devices such as smartphones and tablets.'
    },
    'voice':{
      'languageCode':'en-gb',
      'name':'en-GB-Standard-A',
      'ssmlGender':'FEMALE'
    },
    'audioConfig':{
      'audioEncoding':'MP3'
    }
  }" "https://texttospeech.googleapis.com/v1/text:synthesize" > synthesize-text.txt

我知道了:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   605    0   297  100   308    297    308  0:00:01 --:--:--  0:00:01  3517

然后我打开 synthesize-text.txt 发现

{
  "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"
  }
}

明明gcloud给了我一个token,为什么text-to-speech不能识别?

【问题讨论】:

    标签: google-cloud-platform gcloud api-key


    【解决方案1】:

    [已解决]

    1) 我在“汉堡包”下拉菜单中转到 API 和服务

    2) 我转到左栏中的“凭据”子菜单

    3) 我做了“创建凭据”并选择了 API 密钥 然后在我的要求中,我制定为

    Curl -H "X-Goog-Api-Key: my-newly-created-API-key" -H "Content-Type: application/json; charset=utf-8" --data "{'input' :{'text':'Android是谷歌开发的移动操作系统,基于Linux内核,主要针对智能手机、平板电脑等触屏移动设备设计。'},'voice':{'languageCode':'en- gb','name':'en-GB-Standard-A','ssmlGender':'FEMALE'},'audioConfig':{'audioEncoding':'MP3'}}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > synthesize-text .txt

    现在可以了。

    因此,将“授权承载”与服务帐户密钥一起使用似乎不起作用。 我正在使用 Windows 10。

    【讨论】:

    • 这里是不是引号放错了,我把它放在最后:-H "Authorization: Bearer"$(my_token_is_in_here)
    【解决方案2】:

    就像 Fredrik 在他的评论中所说的那样,Google 的文档中有一个错误,应该是:-H "Authorization: Bearer $(my_token_is_in_here)"(“在末尾,而不是在Bearer 之后)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多