Skip to content

API access using own credentials (server to server flow)

msaniscalchi edited this page Mar 29, 2018 · 7 revisions

This guide will walk you through how to setup OAuth2 for API access using your own credentials using server to server flow.

Step 1 - Creating OAuth2 credentials

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.

Step 2 - Setting up the client library

  1. You can now initialize either an AdWordsClient or DfpClient using the JSON key file you received in the last step. To do so, you should provide an initialized GoogleServiceAccountClient to the AdWords/DFP client via the oauth2_client argument during initialization.

    For example, if you need to set up a DfpClient, it may look something like the following:

    from googleads import dfp
    from googleads import oauth2
    
    
    # Initialize the GoogleRefreshTokenClient using the credentials you received
    # in the earlier steps.
    oauth2_client = oauth2.GoogleServiceAccountClient(
        key_file, oauth2.GetAPIScope('dfp'))
    
    # Initialize the DFP client.
    dfp_client = dfp.DfpClient(oauth2_client, application_name)
    

    For AdWords 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 sub keyword argument.

Clone this wiki locally