|
Free Open Book
Google Hacks |
Hack 72 Blending the Google and Amazon Web Services
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![]() 72.1 How It WorksBook 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.
72.2 The ModulesYou'll need two modules for Book Watch Plus: AmazonAPI and GoogleAPI. 72.2.1 AmazonAPIThe 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 GoogleAPIThe 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 TemplateThere's a sample template available at http://mockerybird.com/bookwatch-plus/bookwatch-plus.txt. 72.4 The CGI ScriptFinally, 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:
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 HackDrop 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.
|
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |