gcloud auth application-default print-access-token错误:" invalid_grant:错误请求"

时间:2017-08-08 21:03:21

标签: google-cloud-platform access-token google-speech-api

我正在尝试为Google Cloud Speech执行tutorial。我成功完成了前两个步骤。第2步的回复是:

Activated service account credentials for: [my-service-account@cloud-speech-quickstart.iam.gserviceaccount.com]

第三步说:

3. Obtain an authorization token using your service account:

gcloud auth application-default print-access-token
access_token

我认为这意味着,请转到您的CLI并输入:

gcloud auth application-default print-access-token

我收到此错误消息:

    ERROR: (gcloud.auth.application-default.print-access-token) There was a problem refreshing your current auth tokens: invalid_grant: Bad Request
Please run:

  $ gcloud auth login

to obtain new credentials, or if you have already logged in with a
different account:

  $ gcloud config set account ACCOUNT

to select an already authenticated account to use.

我认为这告诉我去CLI并输入:

gcloud auth login

然后会打开一个网页,上面写着:

Choose an account
to continue to Google Cloud SDK

我选择了我的Google帐户,然后进入以下屏幕:

Google Cloud SDK wants to
    View and manage your applications deployed on Google App Engine More info
    View and manage your Google Compute Engine resources    More info
    View and manage your data across Google Cloud Platform services More info
Allow Google Cloud SDK to do this?

我点击Allow,然后转到显示

的屏幕
You are now authenticated with the Google Cloud SDK!

然而,该网页并没有给我一个访问令牌。回到命令行,我收到了这条消息:

You are now logged in as [thomasdkehoe@gmail.com].
Your current project is [cloud-speech-quickstart].

看起来很不错,但仍然没有访问令牌。如果我重新进入

gcloud auth application-default print-access-token

我收到原始错误消息。有没有办法摆脱这个循环?我应该试试gcloud auth revoke吗?

1 个答案:

答案 0 :(得分:13)

这恰好发生在我身上,事实证明我需要做

gcloud auth application-default login

(而不是gcloud auth login - 这个不再写入应用程序默认凭据。原始错误消息不正确。)

FWIW将服务帐户用于应用程序默认凭据,我必须这样做 GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_key_file.json