Skip to content

API access using own credentials (server to server flow)

Thanet Knack Praneenararat edited this page Aug 31, 2018 · 4 revisions

This guide will walk you through how to setup OAuth2 for API access using your own credentials using server to server flow. These steps only need to be done once, unless you revoke or delete your OAuth2 credentials.

Step 1 - Creating OAuth2 credentials

Follow the steps for the product you're using to generate a service account with a JSON key file, then come back to this page.

If you're an Google Ads user, please note that this flow requires a G Suite account.

Step 2 - Setting up the client library

Under the [OAUTH2] section of your adsapi_php.ini file, insert the path to your JSON key file and set the scope for the ads API you're accessing. Insert the email account of the user you want to impersonate as, if any.

jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE"
scopes = "INSERT_SCOPES_HERE"
impersonatedEmail = "INSERT_EMAIL_OF_ACCOUNT_TO_IMPERSONATE_HERE"