Ever tried to run a Google Ads API to automate your campaigns but hit a roadblock on getting the OAuth2 Token? This guide is to help you get past that security road block.
You need 3 things to start using Google Ads API
- Google Ads Developer Token
- OAuth2 Token
- Refresh Token
Google Ads Developer Token
- Go to your Google Ads Account
- If you never use Google Ads API, chances are you need to apply for it.
Sign in to your manager account(If you use a Manager Account) and navigate to TOOLS & SETTINGS > SETUP > API Center. The API Center option appears only for Google Ads manager accounts.
Fill up the form and apply
After you’ve completed the application process, the developer token shows up in your API Center with a Pending Approval status.
If your access level is on Test Access, I recommend to request for an upgrade. Standard is the way to go
OAuth2 Token
- Go to Google Cloud Console
- Sign up an account if you don’t have one
- Create a project
- Open the Consent Screen page and select your project in the drop-down menu at the top of the page.
- Select the User Type and click CREATE.
- Fill out the consent screen form. You can edit this later if needed. Click SAVE AND CONTINUE when done.
- On the next page, click ADD OR REMOVE SCOPES.
- Scroll down and enter the following in the field under Manually add scopes:Â
https://www.googleapis.com/auth/adwords
- Click ADD TO TABLE.
- Click UPDATE.
- Click SAVE AND CONTINUE.
- Open the Credentials page. Select a previously created project or create a new one.
- On the Credentials screen, click CREATE CREDENTIALS, then select OAuth Consent Screen
- Select either Desktop app or Web application as the app type, depending on your use case. This guide uses Desktop app as the app type.
- Fill in a name for the app, then click Create.
- On the confirmation page, copy Your Client ID and Your Client Secret to your clipboard for configuring your client library later. Also, download the credentials in JSON format to a file namedÂ
credentials.json
. - Open the API Library in the Google API Console. If prompted, select your project or create a new one. The API Library lists all available APIs, grouped by product family and popularity.
- Use search to find the Google Ads API if it isn’t visible in the list.
- Select the Google Ads API, then click the Enable button.
Pheeww, follow so far? Now the last part!
Refresh Token
The Google Ads API uses OAuth 2.0 as the authorization mechanism. By default, OAuth 2.0 authentication issues an access token that expires after a limited time. To renew the access token automatically, you should issue a refresh token instead.
- Download the pre-compile binaries file based on your OS:Â https://github.com/google/oauth2l#pre-compiled-binaries
- Generate the refresh token by running the oauth2l tool:
oauth2l fetch --credentials credentials.json --scope adwords \
--output_format refresh_token
3. The oauth2l
command opens a Google Account login window in a new browser window and takes you through the OAuth 2.0 authentication steps.
4. After you verify the scopes, grant the permission by clicking the Continue button.
A prompt is displayed in the browser with the following text:
Authorization code granted. Please close this tab.
The oauth2l
command outputs the following JSON snippet:
{
"client_id": "******.apps.googleusercontent.com",
"client_secret": "******",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"refresh_token": "******",
"type": "authorized_user"
}
Note down the refresh_token and you can use that to do your Google Ads API call!
Example of google-ads.yaml(Config file for Google Ads Credential) for python:
client_id: INSERT_OAUTH2_CLIENT_ID_HERE client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE refresh_token: INSERT_REFRESH_TOKEN_HERE developer_token: INSERT_DEVELOPER_TOKEN_HERE login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE
A shameless plug here. I am an advertising professional with a mission to teach others about marketing technology.
If you enjoyed this article, please do consider to clap/follow me, or buy me a coffee here!
Cheers friends!
Pingback: How to use Google Ads API to upload offline conversion - Adsciting
Pingback: How to use Google Ads API to upload audiences for customer match - Adsciting