Google Adwords is a tool to create and manage your ads while the API helps you to do those stuff programmatically. Since Adwords is a paid service, Google provides a Sandbox environment to make our hands dirty by playing with code. To have a quick knowledge about adwords have a glance at my previous post about An introduction to Google Adwords. Adwords has API support in Java, Php, DotNet, Python, Perl, Ruby. Here we are going to look into the API development in PHP. The PHP client library for Adwords is available at Google Code.
Download and unzip the package to your server. Remember this API works only on SOAP enabled servers.
Inside the aw_api folder, you can find a ‘src’ folder, which carries the core files responsible for all the service calls. in the ‘example’ folder, there are pre defined working examples to create/add/delete campaigns, ads, ad groups, etc.,. Before working on that, we need to configure the package to work on sandbox.
For that going to the folder ‘src -> Google -> Api -> Ads -> AdWords’. There you can find two files, ‘auth.ini’ and ‘settings.ini’.
open the ‘Auth.ini’ file:
update the following few lines in that file
email = "<em>youremail</em>@gmail.com" password = "<em>yourpassword</em>" userAgent = "GOOGLE" applicationToken = "USD" developerToken = "<em>youremail</em>@gmail.com++USD" ; Uncomment to make requests against a client account. clientId = "client_1+<em>youremail</em>@gmail.com"
In the above code replace ‘youremail‘ with your Google username and ‘yourpassword‘ with your Google password. Before hand you must have signed up to Google Adwords using that username.
In the settings.php file:
you can find the following lines around the 12th line of the file.
;DEFAULT_SERVER = "https://adwords.google.com" DEFAULT_SERVER = "https://adwords-sandbox.google.com"
Remove the ‘;'(semi colon), before the line that assigns the adwords-sandbox to default_server for working with sandbox environment. After completely developing your App, you can move code live by applying for developer token from Google. Once the developer token is obtained for your MCC account, you can fill your actual developer token in the corresponding variable in ‘Auth.ini’ file and in the ‘clienId’ variable you can fill in the other adwords account you have to manage the ads.
In the settings.php file swap the ‘;’ between the ‘DEFAULT_SERVER’ lines. Thats it now you can explore the API functionalities by running the example files. And Adwords Sandbox doesnt have a GUI so you need to code thoroughly to see the output. Once moving to the live environment all the ads created using API functions will be reflected in the corresponding Campaign.