Skip to content
Hervé Gouchet edited this page Apr 21, 2016 · 1 revision

Google OAuth 2.0

Create a access token to Google Adwords

Create client Id & Secret

  • Connect with your Google account and go to https://console.developers.google.com
  • Click on "Credentials" on the right
  • Click on "Add credentials"
  • Select Oauth 2.0 client ID
  • In application type, select "Other" and give whichever name you want

Then a prompt displays the client_id and the client_secret that we will later refer as YOUR_CLIENT_ID and YOUR_CLIENT_SECRETyour .

Create authorization code

  • Open the following URL in your favorite browser:
https://accounts.google.com/o/oauth2/auth?client_id=YOUR_CLIENT_ID&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&redirect_uri=urn:ietf:wg:oauth:2.0:oob&access_type=offline&approval_prompt=auto
  • Accept the authorization request. Now, you have an authorization code YOUR_AUTHORIZATION_CODE

Get your refresh token

  • In your terminal, execute the following command:
curl \
  -d code=YOUR_AUTHORIZATION_CODE \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET \
  -d redirect_uri=urn:ietf:wg:oauth:2.0:oob \
  -d grant_type=authorization_code https://accounts.google.com/o/oauth2/token

Which will return you a json like this one:

{
  "access_token" : "ya29..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/xxxxxxxxxxxxxxxxxxxxxxx"
}

Now, you have a your client ID & Secret and the refresh token.