OAuth Installed Application Flow

This guide will walk you through how to setup OAuth2 for API access using your own credentials using 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

Generate a client ID and secret by following the linked instructions, then come back to this page.

Step 2 - Setting up the client library

  1. In your google_ads_config.rb file, insert your client ID and secret.

    c.client_id = INSERT_OAUTH2_CLIENT_ID_HERE
    c.client_secret = INSERT_OAUTH2_CLIENT_SECRET_HERE
  2. In a terminal, navigate to the OAuth2 example.

  3. Run this example via the command line. You can either modify the INSERT_XXX_HERE values in the example before running or use arguments -I for client id and -S for client secret.

    $ ruby authenticate_in_standalone_application.rb -Iclientid -Sclientsecret
  4. 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.

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

    Consent screen allow

  5. An authorization code will be shown to you. Copy and paste the verification code into the command line where you're running the authenticate_in_standalone_application.rb example and press enter. The example should complete and display an offline refresh token.

    Authorization code

    After approving the token enter the authorization code here: ****
    Your refresh token is: ****
  6. Copy the generated refresh token into your googleads_config.rb or save it somewhere else to use it to instantiate the library at runtime.