📜 ⬆️ ⬇️

Google AdWords API Example


Many advertisers are aware of the benefits of using the API in contextual advertising. Suppose you need to run an advertising campaign with a large number of similar ads, but for different products. In this case, the API comes to the rescue. You easily and quickly transfer data from the MySQL database to an advertising campaign. And that's it! It is done. You can edit and run a little. This is the scheme we have repeatedly used to advertise our bookstore in Yandex.Direct.

But with Google Adwords, everything was far from easy. We tried for a long time to use this scheme in Adwords, turned over a lot of information on the Internet, until we learned the following from Google support:

AdWords API . .<br>
. , .<br>

Very, very sorry. But we do not lose hope that sooner or later Google will open the possibility to use the API-interface in Russia as well. For such a case, we decided to tell in detail about our example of using the API in Adwords. Our example with a bang worked on a test server of Google, but did not earn on a working server for the above reasons.
This scheme is rather nontrivial, so in the future (when the API for Adwods in Russia will be open) many will make life easier.

Step 1. Create PHP code


First, we create PHP code to transfer data from the MySQL database to AdWords. The latest version of the PHP library can be downloaded from this page . Also, by this link you can find a lot of useful information that is needed in the process of writing code.
')
Our example of using the Google AdWords API to transfer data from the MySQL base of the site to AdWords can be downloaded here as an archive. Note: when downloading this archive to Windows, the NOD antivirus may think for a long time.
This archive contains the following files:

It is worth paying attention that at the moment the latest version of the library is 2.4.1
The example uses the older version - 2.2.0

The code in example.php has comments that should help in developing your version of the exporter. The following describes the basic steps that are performed in the example.

1.1 Initialization of initial parameters

The code block contains the initialization of parameters and the creation of the necessary objects from the aw_api_php_lib_2.2.0 library. While the program is running, the library writes its logs to the ./aw_api_php_lib_2.2.0/src/Logs directory. In addition, the example.php script writes the workflow to its own log file.

1.2 Retrieving data from SQL and populating $ booksArray

In our opinion, this block of code is the most difficult part of the work. In it, you need to implement an algorithm that will turn product information into an AdWords ad. The difficulty lies in applying the same algorithm to generate effective ads for all products.
The example uses the following data export algorithm:
  1. From SQL, information about the book is taken: author, title, url.
  2. From the information about the author formed the title for the announcement.
  3. From the information on the title of the book are formed two text fields for the body of the ad.
  4. From the information about the author and the title of the book, key phrases are formed for the announcement.
  5. The generated information is stored in the $ booksArray array for further sending to the server.

When forming the ad, we do not forget about the Adwords rules:


1.3 Remaining code blocks

The remaining blocks of code in the example, based on the generated data in $ booksArray, create aw_api_php_lib_2.2.0 library objects and send them to the Google server.
The procedure for creating and sending information is as follows:
  1. If necessary, create a campaign or use an existing one.
  2. Create groups that will contain ads.
  3. We add announcements to groups.
  4. In groups add key phrases for ads.


Step 2. Testing the code


For testing, Google provides a special test server on which to test the operation of scripts. To use the test server, do the following:
  1. Create a Google account with a specific email.

  2. Determine which server to use (test or work) in the file ./aw_api_php_lib_2.2.0/src/Google/Api/Ads/AdWords/settings.ini

    To work with the test server you need to put
    DEFAULT_SERVER = "https://adwords-sandbox.google.com"

    To work with a working server you need to put
    DEFAULT_SERVER = "https://adwords.google.com"

    It is worth paying attention to the parameter DEFAULT_VERSION = "v200909" . It determines the version of the library to be used.

  3. Authentication library takes data from the file ./aw_api_php_lib_2.2.0/src/Google/Api/Ads/AdWords/auth.ini
    Sample file content for test server:

    email = "adwords@rekomenda.ru"<br>
    password = "password"<br>
    userAgent = "Rekomenda"<br>
    applicationToken = "ignored"<br>
    developerToken = "adwords@rekomenda.ru++RUB"<br>
    <br>
    ; Uncomment to make requests against a client account.<br>
    clientId = "client_1+adwords@rekomenda.ru"<br>


    Sample file content for production server:

    email = "adwords@rekomenda.ru"<br>
    password = "password"<br>
    userAgent = "Rekomenda"<br>
    applicationToken = "ignored"<br>
    developerToken = "ro_GxDwRQebsFELl34jknEVg"<br>
    <br>
    ; Uncomment to make requests against a client account.<br>
    clientId = "123-456-7890"<br>


  4. Create an account My Client Center (MCC) in the test server. To do this, call the GetCampaignService () method. This method is in the example, so you can not call it separately.



Step 3. Creating My Client Center


We already have a regular AdWords account. But as it turned out, a regular AdWords account is not enough to use the API. To use the AdWords API, you need to create a My Client Center (MCC) and link it to a regular AdWords account.

  1. Create an MCC on this page .
  2. Associate a regular AdWords account with MCC.
  3. At MCC, we set up and activate the AdWords API Center . It is worth noting that when you activate, you can specify that you use the API for your personal business. In this case, you may be provided with free API units. Read more about the cost of units here .


After activating the MCC, the AdWords API Center will look something like this:


The resulting Developer token must be specified in the auth.ini file.
We change the settings of the settings.ini and auth.ini files to use the working server (as mentioned above) and in theory you can start exporting data to the working AdWords.

Step 4. Waiting at the sea weather



When trying to export data not to the test server, but to the working server, an error occurs: INCOMPLETE_SIGNUP_LATEST_NETAPI_TNC_NOT_AGREED

This error just means that the Google Adwords API is not supported in Russia.
Let's hope that the opportunity to use the AdWords API will still appear in Russia.
In future posts, we plan to describe a more successful example of exporting data using the Yandex.Direct API.

UPD In the comments to this topic I was told that in fact the AdWords API in the Russian Federation is available and actively used by many companies. And the support service misled me.
However, it is not possible to pay for the use of the API by credit card. To access, you need to contact those support and arrange a credit line. To do this, you will have to sign the agreement (Terms and Conditions) on paper, in Russian. The agreement can be sent by mail. Those. support then includes manual access.
There is no strictly list of requirements for opening a credit line, part of the requirements can be found here . The decision is made individually, upon request.

UPD 2 This topic was deleted by mistake, but since the information was useful for some users, and besides, new relevant information appeared in the article, I decided to publish the topic again.

Source: https://habr.com/ru/post/112603/


All Articles