-
Notifications
You must be signed in to change notification settings - Fork 768
[Deprecated, old library] API access using own credentials (installed application flow)
This guide will walk you through how to setup OAuth2 for API access using your own credentials using installed application flow. These steps only need to be done once, unless you revoke, delete, or need to change the allowed scopes for your OAuth2 credentials.
- Open the Google Developers Console Credentials page.
- From the project drop-down, choose Create a new project, enter a name for the project, and optionally, edit the provided Project ID. Click Create.
- On the Credentials page, select Create credentials, then select OAuth client ID.
- You may be prompted to set a product name on the Consent screen; if so, click Configure consent screen, supply the requested information, and click Save to return to the Credentials screen.
- Select Other for the Application type, and enter any additional information required.
- Click Create.
- On the page that appears, copy the client ID and client secret to your clipboard.
-
Under the [OAUTH2] section of your auth.ini file, insert your client ID and secret.
client_id = "INSERT_OAUTH2_CLIENT_ID_HERE" client_secret = "INSERT_OAUTH2_CLIENT_SECRET_HERE"
-
In a terminal, navigate to the GetRefreshToken.php example for your product.
-
Run this example via the command line.
This is an interactive example, which will require you to provide input. It will not run properly in a web browser. This example will read the client ID and secret from the auth.ini file we edited in the step above. If your auth.ini file is not in the default location, you will need to edit the example to pass the path to your auth.ini when it constructs a new AdWordsUser or DfpUser.
$ php GetRefreshToken.php Log in to your AdWords or DFP account and open the following URL: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=****&redirect_uri=****&scope=****&access_type=offline
-
The example will prompt you to visit a URL where you will need to allow the OAuth2 credentials to access your AdWords or DFP account on your behalf. Navigate to the URL in a private browser session or an incognito window. Log in with the same Google account you use to access AdWords or DFP. Click Allow on the OAuth2 consent screen.
-
An authorization code will be shown to you. Copy and paste the verification code into the command line where you're running the GetRefreshToken.php example and press enter. The example should complete and display an offline refresh token.
After approving the token enter the authorization code here: **** Your refresh token is: ****
-
Copy and paste this token into your auth.ini file where it says:
refresh_token = "INSERT_OAUTH2_REFRESH_TOKEN_HERE"