PHPBuilder - Search Google Books with the Zend Framework's Zend_Gdata Component Page 2



RSS Twitter
Articles News Reviews

Search Google Books with the Zend Framework's Zend_Gdata Component - Page 2

by: W. Jason Gilmore
|
April 8, 2010

Accessing Book Collections

The Google Books site allows registered users to organize their book collections online, categorizing books according to those identified as favorites, books already read, and books in the reading queue. You can access a particular user's collection using the Zend_Gdata component by prompting the user to log in to his or her Google account. When the user has successfully authenticated, you can retrieve information about his or her collection, including a list of titles, much as you did in the previous example:
try {

  $client = Zend_Gdata_ClientLogin::getHttpClient(
    'wjgilmore@gmail.com', 'secretpassword', 'print');

  $books = new Zend_Gdata_Books($client);

  $feed = $books->getUserLibraryFeed();
} catch (Exception $e) {
  die('An error has occurred:' . $e->getMessage());  
}

if (isset($feed)) {
    echo "<p>{$feed->totalResults} books in collection</p>";

    foreach ($feed as $entry) {
        $link = $entry->getLink();
        echo "<div style='float:left; width: 250px; padding: 5px;'>
              <a href='{$link[1]->getHref()}'>{$entry->getTitle()}</a><br />";
        echo "<img src='{$link[0]->getHref()}' style='float:left;'/></div>";
    }
}
Executing this snippet retrieves the 12 books in my collection, producing the output partially represented in Figure 2. Of course, in a real-world situation, you would prompt the user to provide his authentication information via a web form.



Click here for larger image

Figure 2. Retrieving My Book Collection

Conclusion

The powerful Zend_Gdata_Books class provides a convenient solution for not only accessing Google's vast literary database, but also for actually participating in the service's community by allowing users to manage their book collections in new and unique ways. If you build anything new using this feature, tell us about it in the comments!

About the Author

Jason Gilmore is the founder of EasyPHPWebsites.com and the author of several popular books, including "Easy PHP Web sites with the Zend Framework" and "Beginning PHP and MySQL: From Novice to Professional" (currently in its third edition). Check out his new DZone reference card, titled "Getting Started with the Zend Framework."

« Previous Page
1
|
2

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
W. Jason Gilmore

Comment:



Comment:

(Maximum characters: 1200). You have characters left.