RAdwords: how to access Google Ads API using R

August 17, 2020 in R Programming

In this guide, I’m going to show you how to pull data out of Google Ads using the APIs and an R Package called RAdwords.

Generate the client Id and client secret credentials

Open the Google Developers Console, the platform where you can generate the credentials for every Google API (e.g. Google Analytics API, Google Search Console API, Indexing API,… ) and go to the APIs Library.

Find the Google Ads API and Enable the service. In the credentials section, you can generate the client ID and client secret that you need for the OAuth process.

Click on OAuth client ID and select Web application in order to generate the right credentials for RAdwords.

You have to save somewhere the credentials because you’ll need them in a later step.

Get a Developer Token for the Google Ads API

You also need a developer token which you can get in the Google Ads interface.

Open the Tools & settings menu and go to API Centre.

If you want to work with the Google Ads API in R you’ll need a developer token with at least a Basic Access level, the packages don’t work with a Test Access level.

In order to get a Basic Access token, you have to fill out the application form.

Connect the API and RAdwords using the doAuth() function

Open your R Ide and install RAdwords using the install.packages() function. In order to access the Google Ads API you have to use the doAuth() function which guides you through the OAuth2.0 authentication process.

Run the code above and follow the messages you’ll see in your console, they’ll ask you to enter the credentials you generated earlier:

  1. The client ID from the Google API Console

2. The client secret from the Google API Console

3. The developer token from Google Ads

4. The client token will be generated after you login in your Google Account and granted access to your Google Ads account.

Write your first API Request

If you want to download the data from the Google Ads interface, you have to use getData(). Don’t forget to specify the arguments:

  • clientCustomerId – you have to specify the Id of a Google Ads account. You can’t use the Id of an MCC (manager) account!
  • google_auth – it should contain the credentials you enter with doAuth()
  • statement – an AWQL statement where you specify dimensions, metrics, date range and report. Here you can find the list of all the available fields

Get the same data for multiple accounts

As I said before, you can only use an account ID and not an MCC ID. This could be an issue if you want to get the data from multiple accounts at the same time.

But, you can use a vector and map_dfr() to run the same call over a list of account IDs, here you can find an example.

Write a Comment

Comment

    • Hi!

      Unfortunately, this package works only with the reporting API. But maybe in the future they’ll include specific functions for the Keyword Planner API.