Google Ads API is returning to beta status. Please read our blog post for more details.

Get an OAuth2 Refresh Token and Configure Your Client

Because OAuth2 access expires after a limited time, an OAuth2 refresh token is used to automatically renew OAuth2 access.

Click the tab for the programming language you're using, and follow the instructions to generate an OAuth2 refresh token and set up the configuration file for your client.

Java

  1. Follow these instructions in GitHub to get an OAuth2 refresh token and configure the client library.
  2. Return to this page when you're done. After completing the steps, your ads.properties file should have all you need to make test API calls, and should contain values similar to the following:
    ...
    api.googleads.developerToken=123axxxxxxxxxxxxxxxxxx
    api.googleads.clientId=xxxxxxxxxx.apps.googleusercontent.com
    api.googleads.clientSecret=zZxxxxxTxxxxxxxxxxx
    api.googleads.refreshToken=1/dyOIp7ki-xxxxxxxxxxxxxxxxxxxxxxxx
    ...
    

.NET

  1. Follow these instructions in GitHub to get an OAuth2 refresh token and configure the client library.
  2. Return to this page when you're done. After completing the steps, your app.config file should have all you need to make test API calls, and should contain values similar to the following:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="GoogleAdsApi"
            type="System.Configuration.DictionarySectionHandler"/>
      </configSections>
      <GoogleAdsApi>
        <!-- Settings specific to Google Ads API.-->
        <add key="DeveloperToken" value="xxxxxxxxxxxxxxxxxxxxxx"/>
    
        <!-- OAuth2 configuration -->
        <add key="AuthorizationMethod" value="OAuth2" />
        <add key="OAuth2ClientId" value="xxxxxxxxxx.apps.googleusercontent.com" />
        <add key="OAuth2ClientSecret" value="zZxxxxxTxxxxxxxxxxx" />
        <add key="OAuth2Mode" value="APPLICATION" />
        <add key="OAuth2RefreshToken" value="1/dyOIp7ki-xxxxxxxxxxxxxxxxxxxxx" />
      </GoogleAdsApi>
    </configuration>
    

PHP

  1. Follow these instructions in GitHub to get an OAuth2 refresh token and configure the client library.
  2. Return to this page when you're done. After completing the steps, your google_ads_php.ini config file should have all you need to make test API calls, and should contain values similar to the following:
    [GOOGLE_ADS]
    ...
    developerToken = "INSERT_DEVELOPER_TOKEN_HERE"
    ...
    [OAUTH2]
    ; Required OAuth2 credentials. Uncomment and fill in the values for the
    ; appropriate flow based on your use case.
    
    ; For installed application flow.
    clientId = "INSERT_OAUTH2_CLIENT_ID_HERE"
    clientSecret = "INSERT_OAUTH2_CLIENT_SECRET_HERE"
    refreshToken = "INSERT_OAUTH2_REFRESH_TOKEN_HERE"
    

Python

  1. Follow these instructions in GitHub to get an OAuth2 refresh token and configure the client library.
  2. Return to this page when you're done. After completing the steps, your google-ads.yaml file should have all you need to make test API calls, and should contain values similar to the following:
    google-ads:
      developer_token: INSERT_DEVELOPER_TOKEN_HERE
      client_id: INSERT_OAUTH2_CLIENT_ID_HERE
      client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE
      refresh_token: INSERT_OAUTH2_REFRESH_TOKEN_HERE
      login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE
    ...
    

Ruby

  1. Follow these instructions in GitHub to get an OAuth2 refresh token and configure the client library.
  2. Return to this page when you're done. After completing the steps, your googleads_config.rb config file should have all you need to make test API calls, and should contain values similar to the following:
    Google::Ads::Googleads::Config.new do |c|
      c.client_id = 'INSERT_CLIENT_ID_HERE'
      c.client_secret = 'INSERT_CLIENT_SECRET_HERE'
      c.refresh_token = 'INSERT_REFRESH_TOKEN_HERE'
      c.developer_token = 'INSERT_DEVELOPER_TOKEN_HERE'
    end