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

Susana Argudo

SEM · 16 / 01 / 2020

14 SEM tools to analyze your competition

Tabla de contenidos1 1. Auction Insights (Comparison of auctions)2 2. SpyFu3 3. SEMRush4 4. iSpionage5 5. KeywordSpy6 6. Moat7 7. Adbeat8 8. Similarweb9 9. Minderest10 10. Boardfy11 11. Prisync12 12. Kompyte13 13. Facebook Ad Library14 14. Google Trends 1. Auction Insights (Comparison of auctions) The first of the SEM tools in the list we have within the Google Ads interface itself. Through the Auction Insights or Comparison of auctions, we […]

Marc Salvador

SEM · 09 / 01 / 2020

Google Ads Dictionary

Whether you have just landed in the world of Google Ads (former Adwords) or if you are an experienced Account Manager, it is always good to have a guide with the updated terms of the PPC world at hand. In addition, this Google Ads dictionary will serve as a refreshment and help to understand many […]

Yolanda Sánchez

SEM · 05 / 12 / 2019

TRENDS SEM 2020

You may think that we still have time to finish the year, but the truth is that we are getting closer to 2020. From what we have seen during this year, which has been full of changes and news, we should pay attention to the SEM trends that will govern in 2020 and the new […]

Send this to a friend