-
Notifications
You must be signed in to change notification settings - Fork 977
API access using own credentials (server to server flow)
This guide will walk you through how to setup OAuth2 for API access using your own credentials using server to server flow.
Follow the steps for the product you're using to generate a service account ID and JSON key file, then come back to this page.
If you're an AdWords user, please note that this flow requires a Google Apps Domain.
-
You can now initialize either an
AdWordsClientorAdManagerClientusing the JSON key file you received in the last step. To do so, you should provide an initializedGoogleServiceAccountClientto the AdWords/Ad Manager client via theoauth2_clientargument during initialization.For example, if you need to set up an AdManagerClient, it may look something like the following:
from googleads import ad_manager from googleads import oauth2 # Initialize the GoogleRefreshTokenClient using the credentials you received # in the earlier steps. oauth2_client = oauth2.GoogleServiceAccountClient( key_file, oauth2.GetAPIScope('ad_manager')) # Initialize the Ad Manager client. ad_manager_client = ad_manager.AdManagerClient(oauth2_client, application_name)For AdWords API users, be aware that you must use account delegation with a Google Apps Domain in order to use the Service Account flow. Specify the delegated account with the
subkeyword argument.