Follow US:

Practice English Speaking&Listening with: Getting Started with the AdWords API PHP Client Library

Difficulty: 0

>> KOLEDA: Hi, I'm Eric Koleda with the Google Developer Relations team. This screencast

will show you how to get started with the AdWords API PHP Client Library. The library

requires PHP version 5.2 and the extensions SoapClient, OpenSSL, and cURL. The first thing

we need to do is download the library. The best way to find it is by going to the AdWords

API documentation at From here, click on Docs, Libraries & Samples,

and PHP Client Library. This is the main project page of the AdWords API PHP Client Library.

On the right-hand side of the pages, a convenient link to download the latest version. Once

the download is complete, extract it to a folder of your choice. Before you can start

using the library, you must set the Authentication Information. Browse to Source, Google, API,

Ads, AdWords, and open the file auth.ini. When testing a new library, it's best to use

a SandBox account. More information on the SandBox environment is available in the screen

cast, Intro to the AdWords API SandBox. Entering your SandBox credentials, starting with the

email and password of your Google account, enter a user agent that identifies your application.

The application token itself is ignored in the SandBox. And enter a developer token which

is your email address plus, plus the currency code. Finally, set the client ID to the email

of one the automatically generated client accounts, and save the changes to the file.

Since we are using the sandbox environment, you must also set the default server in settings.ini.

For the Sandbox, this is You are now ready to make a request with the

library. The examples folder contains a subfolder for every version of the API that the client

library supports. To start, we'll open a command prompt, and browse to the examples folder.

The first example we'll run is GetAllCampaigns.php. Since this is a new sandbox account, there

will not be any existing campaigns. To create some campaigns, we'll run AddCampaign.php.

This example added a new campaign to the account, and if we rerun GetAllCampaigns.php, we can

see the return of the results. Now, let's create a new example to pause a campaign.

Create a new file called PauseCampaign.php, and open the text editor. The first thing

we need to do is include the Adwordsphp library. One way to do this is to set the include path

to contain the source code for the PHP client library, and then require the AdWordsUser

class. You don't need to require each service individually because they will be automatically

required by the AdWords user. Next, we'll paste in the try catch loop to ensure that

any errors generated by the library will be caught and displayed. Next, we'll create the

AdWords user object which will load the credentials from the auth.ini set earlier and then enable

logging. The campaign service can be fetched from the AdWords user using the kit campaign

service method. We'll need to set the campaign ID for the campaign we wished to modify. We

go back to the command prompt, we can pull the ID from the previous example.

Next, we'll create the updated campaign object setting the ID to the ID of the existing campaign

and changing the status to paused. Now that we've created the updated campaign object,

we can create the operation that will perform the change. We'll set the operand to the campaign

we just created and the operator to set which will perform an update. Finally, we'll create

an array of operations containing only this one operation. We're now ready to make the

API call which is done by calling the campaign service method mutate passing in the array

of operations. Finally, we'll loop over the results displaying the name, ID, and status

of each of the campaigns that were changed. We'll save this example, go back to our command

prompt, and run the example.

Now we can see there are campaigns where it's updated and has a status pause. Updates to

the library will be announced on a project's homepage. The AdWords API Blog will contain

the information about new services being launched. If you have any questions about using the

API, you can post them to the forum. Finally, if you find any bugs in the PHP client library,

click the Issue in the Issue tracker. Thank you for your time and then enjoy using the

client library.

The Description of Getting Started with the AdWords API PHP Client Library