Get an access token

207 views Asked by At

I tried to get an access token with the google documentation.

curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token? client_id=oauth2-client-id& client_secret=oauth2-client-secret& code=authorization-code& grant_type=authorization_code& redirect_uri=https://www.google.com'

With this request it didn't worked. I added -H 'Content-Length: 0' and now I'm ending up with

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

Anybody have an idea?

4

There are 4 answers

2
zonak53 On BEST ANSWER

If fixing the space didn't work, re-do you linking here from the Google guide, steps 1-6. Then get a new authorization code. I had the same issue and re-linking worked for me (with the -H flag).

0
K20GH On

I've got the same issue.

curl -L -X POST "https://www.googleapis.com/oauth2/v4/token?client_id=<client_id>.apps.googleusercontent.com&client_secret=<secret>&code=4/4wGANiKF5......N0Jg&grant_type=authorization_code&redirect_uri=https://www.google.com"

Stumped

0
Doron W On

it seems you have a space in the request: /v4/token? client_id=oauth2-client-id when i tried to copy past the commands from the documentation it didn't work. i had to re-edit the request before i could use it and it worked.

1
Gijs van Dulmen On

Don't you have to use a different redirect_uri? Your own configured redirect uri?