OAuth Desktop Application Flow

This guide walks you through how to set up OAuth2 for API access using your own credentials in the desktop (installed) application flow. These steps only need to be done once, unless you revoke, delete, or need to change the allowed scopes for your OAuth2 credentials.

Step 1 - Creating OAuth2 credentials

Follow the steps to configure a Google API Console project for the Google Ads API, note the client ID and secret, then come back to this page.

Step 2 - Setting up the client library

  1. In a terminal, navigate to the OAuth2 example.

  2. Run this example using the command line. You can either modify the INSERT_XXX_HERE values in the example before running or use arguments -client_id for client ID and -client_secret for client secret.

    $ perl authenticate_in_desktop_application.pl -client_id {client_id} -client_secret {client_secret}
  3. The example will prompt you to visit a URL where you will need to allow the OAuth2 credentials to access your Google Ads account on your behalf.

    Paste this url in your browser:

    Navigate to the URL in a private browser session or an incognito window. Log in with the same Google account you use to access Google Ads. Click Allow on the OAuth2 consent screen.

    Consent screen allow

  4. An authorization code will be shown to you.

    Authorization code

    Copy and paste the authorization code into the command line where you're running the authenticate_in_desktop_application.pl example and press enter. The example will complete and display your refresh token and some instructions, followed by the properties you'll need to configure the client library:

    Type the authorization code you received here: ****
    Replace the following keys and values in your googleads.properties configuration file:
  5. Copy the generated refresh token along with the client ID, client secret into your googleads.properties or save it somewhere else to use it to instantiate the library at runtime.