OAuth Web Application Flow - googleads/google-ads-perl GitHub Wiki
This guide will walk you through how to setup OAuth2 for API access using your own credentials using web 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.
Step 1 - Creating OAuth2 credentials
Follow the steps to configure a Google API Console project for the Google Ads API.
:star: IMPORTANT: The example below requires that you register the following as one of the Authorized redirect URIs in your project:
http://localhost:8080/oauth2callback
Take note of the client ID and client secret, then come back to this page.
Step 2 - Setting up the client library
-
In a terminal, navigate to the OAuth2 example.
-
Run this example via the command line. You can either modify the
INSERT_XXX_HERE
values in the example before running or use arguments-client_id
for client ID and-client_secret
for client secret.$ perl authenticate_in_web_application.pl -client_id {client_id} -client_secret {client_secret}
-
The example will prompt you to visit a URL where you will need to allow the OAuth2 credentials to access your Google Ads account on your behalf.
Paste this url in your browser: https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=...
Navigate to the URL in a private browser session or an incognito window. Log in with the same Google account you use to access Google Ads. Click Allow on the OAuth2 consent screen.
-
You will be taken to a page with a message indicating that the authorization succeeded.
Authorization code was successfully retrieved.
You'll see that the example completed and displayed your refresh token and some instructions in the same page, followed by the properties you'll need to configure the client library:
Replace the following keys and values in your googleads.properties configuration file: clientId==***********************apps.googleusercontent.com clientSecret=**** refreshToken=****
-
Return to the console where you're running the example, and press
Ctrl + C
to terminate the process. Then copy the generated refresh token along with the client ID, client secret into yourgoogleads.properties
or save it somewhere else to use it to instantiate the library at runtime.