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.

    • Hi Marco,

      right now you can’t download the account ids through RAdwords. Then only way you have is to use a character vector (e.g. copy-paste each single account id or upload a .csv file)

  1. Hi, can you please post how to use this library for the new version. this version is going to be deprecated on April 27 2022.

    • Hi Joel,

      I’m currently writing a new post about a package that works with the new Google Ads API. I’ll keep you updated πŸ™‚