Previous Section  < Day Day Up >  Next Section

9.4. Using Your Google API Key

Every time you send a request to the Google server in a program, you have to send your key along with it. Google checks the key and determines whether it's valid and you're still within your daily 1,000 query limit; if so, Google processes the request.

All the programs in this book, regardless of language and platform, provide a place to plug in your key. The key itself is just a string of random-looking characters (e.g., 12BuCK13mY5h0E/34KN0cK@ttH3Do0R).

If you're going to be making your hack available online for others to use, you might well consider asking visitors to sign up for and use their own Google API key—at least optionally. A thousand queries per day really isn't that much, and should your hack become popular, you'll more than likely have a few unhappy visitors for whom it just doesn't work when you've used up your quota. You can see an example of this in action on Tara's GoogleJack! Page (http://www.researchbuzz.org/archives/001418.shtml): notice the spot in the GoogleJack! form for Google API Key.


A Perl hack usually includes a line like the following:

...

# Your Google API developer's key.

my $google_key='insert key here';

...

The Java GoogleAPIDemo included in the Google Web APIs Developer's Kit is invoked on the command line, like so:

% java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo  

insert_key_here  search ostrich

In both cases, insert key here or insert_key_here should be substituted with your own Google Web API key. For example, I would plug my made-up key into the Perl script as follows:

...

# Your Google API developer's key.

my $google_key='

12BuCK13mY5h0E/34KN0cK@ttH3Do0R

';

...

    Previous Section  < Day Day Up >  Next Section