Google Hacks Free Open Book

Google Hacks

Previous Section Next Section

Hack 72 Blending the Google and Amazon Web Services

figs/expert.giffigs/hack72.gif

A blending of the Google and Amazon web service APIs.

Google doesn't have a lock on the API concept. Other companies and sites, including online bookstore Amazon, have their own APIs. Mockerybird's Book Watch Plus (http://mockerybird.com/bookwatch-plus/bookwatch-plus.cgi) blends the Google and Amazon APIs with a feed of information from the Book Watch service (http://onfocus.com/BookWatch/) to create a list of books, referrals to them in Google, and a list of items that people who bought that book on Amazon also bought. Figure 6-15 illustrates this.

Figure 6-15. Book Watch Plus
figs/gooH_0615.gif

72.1 How It Works

Book Watch Plus does several things to generate its page of information. First, it grabs a page of books most frequently mentioned on weblogs. That list is generated by another service run by Paul Bausch's Book Watch service.

Book Watch Plus wrangles the ISBNs (unique identifiers for books) and then places a couple of calls. The first is to the Amazon web service for detailed information on the book. Then Google is queried via the Google Web API for items related to the book. All this information is aggregated on a regular basis rather than on the fly for each visitor. Results are cached in XML and displayed in the form of a web page via the HTML::Template Perl module.

You might think that with all this fetching and displaying of information, the hack would be a bit involved, and you'd be right. Running the hack requires two modules, a code snippet, and a template. They're all available at http://mockerybird.com/bookwatch-plus/.

72.2 The Modules

You'll need two modules for Book Watch Plus: AmazonAPI and GoogleAPI.

72.2.1 AmazonAPI

The AmazonAPI module is available at http://mockerybird.com/bookwatch-plus/AmazonAPI.pm. You'll have to get yourself a free Amazon Associates account (http://amazon.com/webservices/) before you can use it. Most of the module you can use as it stands, but you will have to make a small alteration to the beginning of the code:

# Your Amazon.com associates id and Web Services Dev Token.
# (learn more about these here: http://amazon.com/webservices/)
my $ASSOCIATE_ID = 'mockerybird';
my $AMAZON_DEV_TOKEN = 'a-token';
# The directory you'd like to store cached asins:
# (it defaults to the same directory as the script, but you'll
# probably want to change that.)
my $XML_DIR = "./";

You'll need to replace mockerybird with your own Amazon Associate ID, and a-token with your own Web Services Development Token.

If you want to have the cached book information stored in a different directory than where the script is located, you'll need to change the my $XML_DIR line to the directory of your choice.

For example, if your associate ID were tara, developer token googlehacks, and preferred cache directory /home/tara/google/bookwatchplus/cache, those lines should read:

# Your Amazon.com associates id and Web Services Dev Token.
# (learn more about these here: http://amazon.com/webservices/)
my $ASSOCIATE_ID = 'tara';
my $AMAZON_DEV_TOKEN = 'googlehacks';
# The directory you'd like to store cached asins:
# (it defaults to the same directory as the script, but you'll
# probably want to change that.)
my $XML_DIR = "/home/tara/google/bookwatchplus/cache";

(Note the changes highlighted in bold.)

72.2.2 GoogleAPI

The GoogleAPI.pm module is available at http://mockerybird.com/bookwatch-plus/GoogleAPI.pm. You'll have to make a couple of changes to this module as well; the lines you're after are:

package GoogleAPI;
# The directory you'd like to store cached asins:
# (it defaults to the same directory as the script, but you'll
# probably want to change that.)
my $XML_DIR = "./"; # <-- PUT A DIRECTORY HERE TO STORE XML
# Get your Google API key here:
# http://www.google.com/apis/download.html
my $key = ""; # <-- PUT YOUR KEY HERE

Just like the AmazonAPI, you'll have an option to change the directory to which cached information is saved. If you want to change the directory (by default, the information is saved in the same directory where the script is installed) change the my $XML_DIR line. You'll also need to put your Google developer's key on the my $key = ""; line.

If your Google Web API developer's key were 12BuCK13mY5h0E/34KN0cK@ttH3Do0R and preferred cache directory /home/tara/google/bookwatchplus/cache, those lines should read:

package GoogleAPI;
# The directory you'd like to store cached asins:
# (it defaults to the same directory as the script, but you'll
# probably want to change that.)
my $XML_DIR = "/home/tara/google/bookwatchplus/cache"; 
# <-- PUT A DIRECTORY HERE TO STORE XML
# Get your Google API key here:
# http://www.google.com/apis/download.html
my $key   = "12BuCK13mY5h0E/34KN0cK@ttH3Do0R"; 
# <-- PUT YOUR KEY HERE

(Note the changes highlighted in bold.)

72.3 The Template

There's a sample template available at http://mockerybird.com/bookwatch-plus/bookwatch-plus.txt.

72.4 The CGI Script

Finally, you'll need the CGI script itself; it's available at http://mockerybird.com/bookwatch-plus/bookwatch-plus-cgi.txt. You'll need to change several variables on the CGI script. They're listed at the beginning of the script and are as follows:

$default_book_rss_feed_url

The RSS feed you want as the default for the hack

$book_display_template

The default template with which you want to display the Book Watch items

$number_of_items_in_list

Number of items to display

$number_of_google_results

Number of results from Google (defaults to 5)

$number_of_amazon_similarities

Number of similar items listed at Amazon (defaults to 5)

$xml_cache_directory

Where to store the XML cache materials

$num_minutes_to_cache_rss_feeds

For how long your RSS feeds should be stored before being refreshed

In addition to these variables, you can alter the list of RSS feeds used by the site, from which the program gets its book information. If you don't have any RSS feeds in mind, leave the ones that are here alone and don't alter the $default_book_rss_feed_url above.

72.5 Running the Hack

Drop the CGI script (bookwatch-plus.cgi), the two modules (AmazonAPI.pm and GoogleAPI.pm), and the template file (bookwatch-plus.txt) into place. Invoke the CGI script from your browser and enjoy.

Bookwatch Plus application written by Erik Benson.

    Previous Section Next Section


         Main Menu
    Main Page
    Table of content
    Copyright
    Dedication
    Credits
    Foreword
    Preface
    Chapter 1. Searching Google
    Chapter 2. Google Special Services and Collections
    Chapter 3. Third-Party Google Services
    Chapter 4. Non-API Google Applications
    Chapter 5. Introducing the Google Web API
    Chapter 6. Google Web API Applications
    6.1 Hacks #60-85
    6.2 The Ingenuity of Millions
    6.3 Learning to Code
    6.4 What You'll Find Here
    6.5 Finding More Google API Applications
    6.6 The Possibilities Aren't Endless, but They're Expanding
    Hack 60 Date-Range Searching with a Client-Side Application
    Hack 61 Adding a Little Google to Your Word
    Hack 62 Permuting a Query
    Hack 63 Tracking Result Counts over Time
    Hack 64 Visualizing Google Results
    Hack 65 Meandering Your Google Neighborhood
    Hack 66 Running a Google Popularity Contest
    Hack 67 Building a Google Box
    Hack 68 Capturing a Moment in Time
    Hack 69 Feeling Really Lucky
    Hack 70 Gleaning Phonebook Stats
    Hack 71 Performing Proximity Searches
    Hack 72 Blending the Google and Amazon Web Services
    Hack 73 Getting Random Results (On Purpose)
    Hack 74 Restricting Searches to Top-Level Results
    Hack 75 Searching for Special Characters
    Hack 76 Digging Deeper into Sites
    Hack 77 Summarizing Results by Domain
    Hack 78 Scraping Yahoo! Buzz for a Google Search
    Hack 79 Measuring Google Mindshare
    Hack 80 Comparing Google Results with Those of Other Search Engines
    Hack 81 SafeSearch Certifying URLs
    Hack 82 Syndicating Google Search Results
    Hack 83 Searching Google Topics
    Hack 84 Finding the Largest Page
    Hack 85 Instant Messaging Google
    Chapter 7. Google Pranks and Games
    Chapter 8. The Webmaster Side of Google
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele