TV

Free Affiliate Programs - an instrument to earn money online

Google

Monday, October 6, 2008

Google Web API Tutorial

If you always wanted to give the Google Web API a try, but never did, I'd like to give you a small step-by-step tutorial.
What is the Google Web API?

The API* exposes the Google engine to developers. This means you can write scripts that access the Google search in real-time. For example, you could query all pages containing "hello", and output the page-count. Or anything else imaginable.
Limitations

You have a default limit of 1,000 queries per day, you cannot get over the 1,000th result, you can only query for 10 results a time, and you can only access Google Web Search (not Google Images, Google Groups, and so on).

* Depending on the source, the abbreviation "API" stands for Application Programming Interface, Application Programmer's Interface, Application Programmer Interface, Application Program Interface, or Application Programmatic Interface. In short, it's a wrapper around a program that helps developer's to easily access its inner functionality. The Google Web API is also called "Google Web Services".
Do I have what it takes?

What you need is a server that allows you to execute server-side scripts. If you got www.example.com, you should check your contract and wether or not you can do that; email your host support if in doubt. Ask them if they have CGI, scripting like PHP, Pythôn, Java, ASP, or the like.

Second, you need to know the programming basics. But using the Google Web API is not very complicated, as there are several wrapping tools to get you started.

For this small tutorial, I will give examples of a PHP implementation. You can use other languages as well (like Perl). You should be familiar with HTML as well. PHP is a language, besides other things, to dynamically create HTML pages.

The Google API (currently in Beta) is further based on the Web Services technology SOAP (the XML-based Simple Object Access Protocol). But you don't need to details of SOAP to use the API, really.
Downloading the API, and registering for a key.

Create your own folder on your computer and put all the needed files in it; first, you should download the toolset of the Google Web API (note that you don't need it for this sample), and get your developer key (which you do need for the sample):

*

Visit the Google Web API home and download the API tools (below 700K).
*

Get your developer's key by creating a Google account and write it down. You shouldn't pass it on to anyone else. It's like a personal password to make the Google Web API work.

Second, get the helpful file called "NUSOAP" by Dietrich Ayala. It's free and helps you to implement a Google Web API script in PHP. (Note that I put NUSOAP on my server because I made a small but important change to the file which was necessary to get the filter-parameter to work.)

Now that everything's unpacked and waiting in your folder, create your own test project by creating a sub-folder called "test". Put the "nusoap.php" file in the folder.
Next, use Notepad – or another text-editor, like my Netpadd – and write the following testing PHP script as "index.php" and upload it to your server via FTP (you can use Absolute FTP for that; it's free to test for 30 days):

amazon