Hide

Generating OAuth tokens with the OAuth 2.0 Playground

Overview

If you're having trouble generating an OAuth refresh token or access token using the AdWords API client libraries, another option is to use the OAuth 2.0 Playground. The playground, in conjunction with the Google Developers Console, allows you to manually create OAuth tokens. This document outlines the steps for generating tokens via the playground.

The steps here are a good fit for users who only need to access the accounts for a single manager account or AdWords user. If you need to prompt multiple users for credentials, then the client library-based approach is probably a better fit for you.

Step 1 - Get a client ID and client secret

  1. Go to https://console.developers.google.com.
  2. If you already have a project in the console, click on it in the console. Otherwise, click Create Project and fill out the required fields.
  3. Expand APIs & Auth, then click Consent screen. If you have not filled out all required fields, please do so and click Save.
  4. Under APIs & Auth, click Credentials.
  5. Under OAuth, click Create new Client ID.
    1. Choose Web application.
    2. Under Authorized redirect URIs, add a line with: https://developers.google.com/oauthplayground
    3. Click Create Client ID.
    4. On the page that appears, take note of the Client ID and Client secret. You'll need these in the next step.

Step 2 - Generate tokens using the OAuth 2.0 Playground

  1. Go to the OAuth 2.0 Playground via this link, which should pre-populate some key values for you.
  2. Click the gear icon in the upper right corner and check the box labeled Use your own OAuth credentials if it isn't already checked, then:
    • Make sure that:
      • OAuth flow is set to Server-side.
      • Access type is set to Offline (this will ensure you get a refresh token and an access token instead of just an access token).
    • For the OAuth Client ID, enter the Client ID obtained in step 1.
    • For the OAuth Client secret, enter the Client secret obtained in step 1.
  3. Under Step 1 - Select & authorize APIs, enter the following in the Input your own scopes text box if it's not already there:
    https://www.googleapis.com/auth/adwords
  4. On the left side, click Authorize APIs.
  5. If prompted, log in to the account to which you want to grant access and authorization. Otherwise, confirm that the current Google user in the top right corner is the AdWords or manager account for whom you want to obtain credentials.
  6. If you only performed Step 1 a few minutes ago and you get an error of the form Error: redirect_uri_mismatch, it may be that the changes you made haven't yet propagated. Click the back button in your browser and wait a few minutes, then try clicking Authorize APIs again.
  7. You will see a prompt that says that your application would like to Manage your AdWords Campaigns. Click Accept to continue.
  8. Under Step 2 - Exchange authorization code for tokens, you should now see an Authorization code filled in.
  9. Click Exchange authorization code for tokens.
  10. If all goes well, you should see the following filled in for you (you may have to re-expand Step 2 - Exchange authorization code for tokens to see these values):
    • Refresh token
    • Access token
  11. Copy the Refresh token into the configuration file for your client library of choice. Also make sure you put the Client ID and Client secret in the configuration file. See the client library OAuth documentation for instructions on how to set configuration options for your client library of choice.

Step 3 - Remove the OAuth 2.0 Playground from your Client ID

Now that you have a refresh token, you no longer need the OAuth 2.0 Playground to be an authorized redirect URI. If you want to remove it from the list of authorized redirect URLs:

  1. Go to https://console.developers.google.com.
  2. Click on your project.
  3. Under APIs & auth -> Credentials, find your Client ID and click Edit settings.
  4. Remove https://developers.google.com/oauthplayground from the Authorized redirect URIs. Note that you must leave at least one redirect URI in place.
  5. Click Update.

Congratulations! You now have OAuth credentials you can use to issue AdWords API requests. You can now try out the examples for your client library of choice.

Send feedback about...

AdWords API