Google API and PHP
Stephen Martin
Findability Presentation
The Process
In order to use the Google API, you have to follow their 3 step process.
Download the Developers Kit
- Dowload the developer's kit which includes all of the files you'll need from Google's side of the process. You can write your program in your chosen language.
- This presentation focuses on PHP, but you could use .NET, Java or any other language that can connect to web services through SOAP.
Create a Google Account
- In order to use the API (free) you will need a Google account (free).
- If you use GMail or any other Google service, you already have an account!
- The account will allow you to perform 1000 queries per day.
Account Process
Write your program
- Build your program and be sure to use the license key you received in step 2.
- This is what it looks like: (Don't steal mine, you can get your own for free)
What can I do?
- You are only limited to the features of a Google search - which leaves a lot of open ended possibilities. Take a look at the extensive reference link at the end of this presentation.
- Google gives some brief recommendations of things you can do with the Google API
- An Example: Use the spell check feature of Google somewhere in your web application or site
- An Example: Monitor a search you perform on a regular basis, like "New PHP Classes "
SOAP and WSDL
- The Google API is a Web Service that is built on SOAP and WSDL
- SOAP stands for Simple Object Access Protocol
- WSDL stands for Web Service Description Language
What are Web Services?
- A web service is a network interface to application functionality (huh?)
- It's much easier to understand when thought of as "functions you can call over the internet"
- SOAP acts as the delivery service, WSDL describes what is being delivered
- In the case of the Google API - the functionality of Google (search capabilities and more) are what is being delivered.
- Google provides a WSDL file in the developer kit
Using NuSOAP
- NuSOAP is a simple, free, PHP class that facilitates the use of web services via SOAP.
- An alternative to the SOAP PEAR Package (No server installation required).
- Include the file in your PHP script, instantiate a NuSOAP object and call your web services functions
PHP 5 and SOAP
- Experiencing problems? Maybe you have PHP5 (I did... and NuSOAP had a fit.)
- PHP5 has a built-in SOAP extension, NuSOAP is not required.
- No includes are necessary if the SOAP extension has been activated on your server (it's not active by default)
Sample Search
- This example uses PHP5 and the installed SOAP extension.
- Example calls the Google API to search for "ipod" and returns a resultElements array.
- Within that array are arrays for each of the results containing items like URL and title.
- Run the Example