This guide walks you through how to set up OAuth2 for API access using your own credentials in the desktop (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.
Step 1 - Creating OAuth2 credentials
Generate a client ID and secret by following the linked instructions, then come back to this page.
Step 2 - Setting up the client library
google_ads_config.rbfile, insert your client ID and secret.
c.client_id = INSERT_OAUTH2_CLIENT_ID_HERE c.client_secret = INSERT_OAUTH2_CLIENT_SECRET_HERE
In a terminal, navigate to the OAuth2 example.
Run this example using the command line. You can either modify the
INSERT_XXX_HEREvalues in the example before running or use arguments
-Ifor client id and
-Sfor client secret.
$ ruby authenticate_in_desktop_application.rb -Iclientid -Sclientsecret
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.
- Navigate to the URL in a private browser session or an incognito window.
- Sign in with the same Google account you use to access Google Ads.
- 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
authenticate_in_desktop_application.rbexample 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 the generated refresh token into your
googleads_config.rbor save it somewhere else to use it to instantiate the library at runtime.