This guide uses a client library to retrieve Google Ads campaigns.
To enable API access, first obtain the required OAuth2 credentials. Then, add the authorization and account details to a config file. Once the config file is set up, you're ready to call the API.
You'll need to supply the following information in the config file of your client library.
- Developer token
Your developer token lets your app access the API, but the token is not restricted to only one Google Ads account. Once your token is approved, you can use the same token for requests against all your Google Ads accounts, even if they're not linked to the Google Ads Manager Account associated with the token. The accounts you manage are authorized by OAuth credentials from the manager account. A manager account requires only one set of credentials to manage all of its sub-accounts.
Only approved tokens can connect to the API for production Google Ads accounts; pending tokens can connect only to test accounts.
You can retrieve your developer token by signing in to your manager account then navigating to the API Center (TOOLS & SETTINGS > SETUP > API Center).
- A company should have only one developer token.
- Once a client ID from a Google Cloud project is used with a developer
token, the client ID is bound to the developer token and can't be used
with another developer token. In other words:
- A developer token can be used with multiple client IDs.
- However, a client ID can be used with only one developer token.
- Client customer ID
The client customer ID is the account number of the Google Ads client account you want to manage with the API, usually in the form
Optionally, the client customer ID can be left out of the config file and set programmatically. Once your developer token is approved, you can use a client customer ID from a production account instead of a test account.
- OAuth2 client ID and client secret
The OAuth2 client ID and client secret map your client app to a project in the Google API Console and are used for OAuth2 authentication—allowing your app to operate on behalf of your account. They identify your app to Google and allow you to generate OAuth tokens for managing Google Ads users.
Consult Create a client ID and client secret for more details.
- OAuth2 access and refresh tokens
Before your app can access private data using the API, it must obtain an OAuth2 access token that grants access to the API.
If you're using the client libraries, the OAuth2 access token is automatically taken care of for you. Otherwise, check out the API call example in the OAuth2 guide for details on how to generate an access token.
OAuth2 access tokens expire after a limited time. For this reason, the client libraries use the OAuth2 refresh token to automatically regenerate the OAuth2 access token.
OAuth2 access and refresh tokens has instructions for creating the refresh token.