AdWords API: First Steps

The Google AdWords application Programming Interface (API) is designed for developers who represent important advertisers or third parties with extensive technical experience.

What utilities does the AdWords API offer?

  • Automatically generate keywords, ad text, target pages, and custom reports.
  • Integrate AdWords data with inventory system to manage stock-based campaigns.
  • Develop additional tools and applications to help you manage your accounts

Set up the AdWords API

To start using the AdWords API, you need to get a developer token in the MCC account or Administrator Account.

To apply for the developer token, go to the account settings.

Configuración AdWords

AdWords SetUp

Once we access the account settings, we have to access the “AdWords API Center”.

When we connect, we will see a form to fill in and so request that they give us a programmer token needed to work with the AdWords API.

Solicitar acceso API AdWords

Request AdWords API Access

Once the access is requested the screen will be updated and our “Programmer Token” will appear in test accounts mode.

Token programador API AdWords

To work with the AdWords API on this account, you need to apply for basic access, but in this case, we will start working with the API, with a TEST account in AdWords.

AdWords TEST Account

To create a test-type account in AdWords, you need to fill in the Google form To create this type of account.

Formulario Test API AdWords

Once we have created the Test account, we will see that when accessing AdWords, a message appears telling us that we are a test type account.

Cuenta Test

Cuenta Test

With the MCC Test account created, we will create an AdWords account associated to our MCC Test account. In this account is where we will do all our tests with the AdWords API.

Client ID API AdWords

Client ID API AdWords

Once we have it, we keep the client ID of the account, for later use it.

Now we will create some credentials to use the Google APIs, in our case for the Adwords API.

OAUTH2 Accreditation for Developers

Google APIS use credentials to use these APIS.

To get those credentials we have to address the Developer Console.

As we are going to use the test type account that we have just created, we log into the developer console with that account (when we are going to use the API with the normal account, we will have to do the same).

Console API Google Credentials

Console API Google Credentials

Already logged in, we access the menu “Credentials”, if we do not already have a project created, will ask to create a new project.

Click on “Create a project”, indicate the name you want and click on Create.

OAuth Credentials

OAuth Credentials

Now that we have created our project, we can create the credentials we wanted. To do this, in “Create credentials”, select “OAuth client ID”.

In the form that will appear to us, we select “Other” and add the name that we want to assign to him. And once we create it, We will have our credentials!

Credenciales OAuth API Google Console

Credentials OAuth API Google Console

We will see our customer ID, and the client’s secret.

We save this data for later and we will be closer to start using the AdWords API .

Get the client library

The AdWords API platform allows us to use this API with different programming languages, in our case we will use PHP.

In addition to PHP also include the libraries of JAVA, PYTHON, etc…

    • To download the library in PHP, you have to download the files from Github.
    • If you want to download from other languages, you can do it from here

Now we just have to start the API.

API settings

Now that we have the library, we will modify the configuration file, in this file will be added the credentials and the necessary account data.

The file is called auth.ini and is located at:

googleads-php-lib / src / Google / API / Ads / AdWords / auth.ini

If we edit it, we will see that there are several commented lines and that we ask for certain information in the variables.

Auth.ini

Auth.ini

        • DeveloperToken: In this variable we have to add the developer token that we ordered in our production account.
        • clientCustomerId: This line is commented, as we will start with the account type test, we will uncomment and add the identifier of the account we had created previously. If when we are in production we want to work with several accounts, just comment and pass that identifier in a dynamic way.
        • client_id: Here we have to insert the identifier of the credentials OAuth we already have created.
        • Client_secret: Here we have to include the secret also obtained from OAuth.
        • Refresh_token: This is the last data that we lack, to obtain it we have to execute in console The file GetRefreshToken.php.

      Get Refresh_token:

      First we save the file auth.ini with the credentials that we have already inserted.

      Open the console or terminal of our operating system, in my case I will use the Windows console (cmd).

      From the console we access the path where that directory is, for this we execute the following command:

      php googleads-php-lib-masterexamplesAdWordsAuthGetRefreshToken.php

      When you run it, you will ask us to connect to our AdWords account (in this case in our test type account) and access a URL.

      Do not close the console because then we will have to paste the code back!

Consola GetRefreshToken

Consola GetRefreshToken

If the URL appears somewhat like INSERT_OAUTH2_CLIENT_ID_HERE, it means that we have not saved the auth. ini file with the credentials data.

Therefore when we execute the indicated command, we have to notice that the URL that returns us, contains in that client ID section.

Permisos API AdWords

Permisos API AdWords

If everything goes correctly, Google will ask permission to manage our AdWords campaigns.

When we accept the permissions, we will see a code, we have to copy and paste it in the execution of the command we just made in console.

Paste the code where indicated, press enter and… our refresh_token will appear!

Refresh Token API AdWords

Refresh Token API AdWords

Now this code, we include it in the file auth. ini and we will have configured and running the AdWords API!

AdWords API Execution

To start using the AdWords API, we will use the examples files that appear in the downloaded library.

Let’s run the example that creates new campaigns. To do this, we go to the console, and run the file AddCampaigns. PHP, located in:

examplesAdWordsv201609BasicOperations

AdWords API Example

AdWords API Example

By default these files are only run in console, but if you want to run them in a server environment, we have to comment on these lines of code.

if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {   return; }

And so far the process of configuring the AdWords API is a somewhat long process but the result is well worth it.

For any questions do not hesitate to ask! Also, here I leave the reference of the AdWords API. Good luck!

Written by

DigitalMenta

SEM · 08 / 11 / 2016

Did you like it?

Get a quote

Andrea Sapiña

SEM · 12 / 03 / 2020

Search network vs Display network: what should I use in Google Ads campaigns?

I want to do AdWords campaigns but, in which Network, Search or Display? Once we decide to advertise with AdWords campaigns, it is often the case that we face different networks and types of campaigns without knowing how to choose the one that best suits our objectives. Should I do Search Network campaigns? Or maybe […]

Maria Roca

SEM · 27 / 02 / 2020

Advertising on YouTube

Are you thinking of advertising on YouTube? We explain why this is a good decision. YouTube is a social network with a great reach, these are some facts that will show you how it stands today and will make you think why you should advertise on YouTube: More than one billion users. More than 400 […]

Jorge Sanchez

SEM · 13 / 02 / 2020

Start your first campaign in Amazon Ads

Today, Amazon has become the largest Marketplace in the world.  If your business is based on e-commerce, Amazon may be a very important strategic and sales channel for you. The competition within it is increasing, have you thought about using campaigns from Amazon ads to increase your sales opportunities? Throughout the following post I will […]

Send this to a friend