Getting OAuth 2.0 Access Token for Google AdWords API access

Accessing AdWords data via the Google AdWords API can be confusing and complicated, especially with the way Google Services API OAuth works.

In order to access AdWords via API, you'll (or your codes)  need to be authenticate via through OAuth 2.0. This guide is focusing on getting the OAuth Access Token so that you can call the API from your codes.

To do this, we'll first need to create a credential (a.k.a. a Client ID) to access the API. Google's API credentials are manage with Google Developer Console.

  1. Create New Client ID using Google Developers Console
    - follow the steps here, under "Create a client ID and client secret" section.

  2. During the Step #7, choose Web application and enter the following:


    • "https://developers.google.com" in AUTHORIZED JAVASCRIPT ORIGINS



    • "https://developers.google.com/oauthplayground" in AUTHORIZED REDIRECT URIS




  3. Save and you will see the Client ID being created.


Next, we're going to get a token for our API calls. This actually involves getting an Authorization code, a Refresh token and an Access token (this Access token is essentially what we need to make API calls).


  1. Head over to https://developers.google.com/oauthplayground, click on the "gear icon" on the top right corner and you'll see a dialog showing up.

  2. Check "Use your own OAuth credentials", and enter accordingly. The Adwords API is NOT in the selection (as when this post is written), so you need to manually input "https://adwords.google.com/api/adwords" in the "Select & authorize APIs" input field. You'll also need the Client ID information that you previously generate.

  3. Click the "Authorize APIs" button and login with your AdWords Account when prompted (only if you're not already logged in)

  4. You will then be redirected back to the OAuth 2.0 Playground's step 2; at this point, an Authorization code has been generated for the Client ID.

  5. Click on "Exchange authorization code for tokens" button, and the Access token will be generated for you. There will be a counter telling you when the Access token is going to be expired and you'll need to click the "Refresh access token" to renew it.

  6. That's it, that's your OAuth 2.0 Access token for Google AdWords API.


Comments

Post a Comment