Home > database >  How to get Google API refresh_token from code
How to get Google API refresh_token from code

Time:02-03

I try to get refresh token from code. Here is curl I use:

curl --request POST --data "code=4/0AWtg..&client_id=977..&client_secret=GOC..&redirect_uri=htt..&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token

returned value is

{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

What is wrong and how to get refresh_token from code, please? Thank you.

CodePudding user response:

invalid_grant is one of the most frequent oauth errors. It can be caused by a number of things.

  1. the code was already used
  2. your PC time isn't set to NTP
  3. The code and the client id don't match.

This is the code I use GoogleAuthenticationCurl.sh

curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=http://127.0.0.1&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token

Understand Google OAuth with curl

  • Related