Google Advertising Tools: Cashing in with Adsense, Adwords, and the Google APIs
14.1. Using the AdWords API with PHP
The web application in this chapter is programmed using PHP. PHP is most commonly used for programming in web applications. PHP pages on the Web are HTML pages with PHP code embedded in the HTML. This makes PHP great for web programmingafter all, it is used by more than 20 million web domainsbut not always the best language choice for all applications.
Case in point: as you'll come to understand as you follow along with the code listings in this chapter, PHP does not interact easily with the document literal style of SOAP web services offered by the Google AdWords API. This means you'll have to go through some contortions to make PHP play nicely with the AdWords API.
Several other languages and development environments do a good job of encapsulating the messiness of document literal SOAP from programmers who are writing applications that consume these web services. Specifically, Visual Studio.NETand one of the .NET languages such as VB or C#or Java (combined with the Apache Axis library) make it very easy to program with the Google AdWords API. These tools hide the details of the SOAP interaction by generating proxy classes. The programmer can focus on working with the high-level objects instantiated from these classes, rather than worrying about the details of the SOAP handshake.
To summarize, if .NET or Java/Axis works well with your other systems, perhaps because you or your business is already programming in one of these environments, then these languages would be the best choice for working with the Google AdWords API. Despite the ease of using these other languages with AdWords, I've chosen to show the examples in this book in PHP, which is a nice language for web development, even if it's not so good for working with the AdWords API. If I had written the examples using C# .NET or Java, it wouldn't have been as useful to readers unfamiliar with these languages and their development environments. PHP is accessible to almost any programmer. It's free (well, so is Java!) and it runs on every flavor of operating system, so no one is ruled out. And PHP is as good as any other environment for learning about the different services that comprise the AdWords API, the classes that comprise the services, and how they interact. 14.1.1. SOAP Libraries for PHP
SOAP libraries , also called SOAP toolkits, are used to interpret WSDL files (see Chapter 13 for information about WSDL files). These libraries also provide tools that help encode and decode XML request and response messages. The two SOAP libraries available for use with PHP are PEAR and NuSOAP (both are free to use). PEAR generates RPC-encoded XML as its output message, whereas NuSOAP can be made to generate document literal XML to be used with SOAP, making NuSOAP the better choice for working with the Google AdWords API web services.
14.1.2. Downloading and Installing NuSOAP
The NuSOAP toolkit consists of a primary file, nusoap.php, and 12 supporting files, all containing PHP code. You must have all these files in order to use NuSOAP. You can download a zipped archive containing the complete NuSOAP files, documentation, and samples from http://sourceforge.net/projects/nusoap/.
It's most common to write PHP code to a file on your local computer, using a text editor or an editor specifically intended for programming, and then upload the file to your web server and run it from that server. Assuming this is the approach you're taking, follow these steps to get NuSOAP working with your PHP installation and development environment:
|