Got error whenever trying to get access token from service account

后端 未结 1 911
南笙
南笙 2021-01-23 14:05
INFO: com.google.api.client.auth.oauth2.TokenResponseException: 400 OK
{
  \"error\" : \"invalid_grant\"
}

my code is

GoogleCredential          


        
相关标签:
1条回答
  • 2021-01-23 14:27

    Possible reasons:

    1) I was having a similar problem caused by the time on my server being incorrect. Make sure your system clock is synchronized.

    2) You should reuse the access token you get after the first successful authentication. You will get an invalid_grant error if your previous token has not expired yet. Cache it somewhere so you can reuse it.

    3) Make sure that you pass the access token, and not refresh token as that fails. When you run, it turns the OAUth2 refresh token into an access token and passes that to the service. If you pass the raw refresh token, this is not acceptable for API access without turning it into a short-lived access token.

    4) You might have reached the refresh token limit. Certain Google APIs have this, some explanation you can find here: https://developers.google.com/compute/docs/authentication

    5) You also can revoke it. Go to your Google API Console ( https://code.google.com/apis/console/ ) and revoke your Client Secret under Client ID for installed applications. Be sure to also update your code with the new Client Secret

    0 讨论(0)
提交回复
热议问题