how to get token from google api?

Viewed 520

ım using rest api to generate access token and refresh token from google api

the tutorial that ı follow is here

when ı try to send curl ı got this error

  "error": "unsupported_grant_type",

"error_description": "Invalid grant_type: "

ı found this sloution on stackoverflow link but didnt work . here is my curl

curl -d "code=4/0AY0e-g4NhDiqBSToonAVCsw9JglcffbxGie1bssXcAKLuRDB7KYDluta7ZpNvHEoqylJyw&client_id={client_id}&client_secret={client_secret}=https://api.dev.example.net&grant_type=authorization_code" -H "Content-Type: application/x-www-form-urlencoded" -X POST https://oauth2.googleapis.com/token
1 Answers

Getting an access token from Google with curl takes a few steps

Request consent of the user

# Client id from Google Developer console
# Client Secret from Google Developer console
# Scope this is a space seprated list of the scopes of access you are requesting.

# Authorization link.  Place this in a browser and copy the code that is returned after you accept the scopes.
https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=[Scopes]&response_type=code

Authorization code exchange

# Exchange Authorization code for an access token and a refresh token.

curl \
--request POST \
--data "code=[Authorization code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token

Exchange refresh token for new access token

# Exchange a refresh token for a new access token.
curl \
--request POST \
--data 'client_id=[Application Client Id]&client_secret=[Application Client Secret]&refresh_token=[Refresh token granted by second step]&grant_type=refresh_token' \
https://accounts.google.com/o/oauth2/token
Related