DevWebProSE
DevWebProSE Newsletter:
Last Updated:


Get Your Site Submitted for Free in the World's Largest B2B Directory!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions


New Picasa API From Google

By Philipp Lenssen
Expert Author
Article Date: 2007-03-26

Google released a new API: the Picasa Web Albums Data API for photos.



Using this API, which is part of the "GData" framework (which itself makes use of Atom feeds), you can include your photos on web pages or manage them from within other applications, among other stuff.

One of the most straightforward, read-only uses is to simply request the contents of a public album to display its images. You'll use the following URL return a "REST"-style XML:

http://picasaweb.google.com/data/feed/api/
user/philipp.lenssen/album/55WaysToHaveFunWithGoogle


... where the first bold parameter is the user ID, and the second bold parameter is the album name. Here's a small sample function in PHP5, which generates this output:

function showAlbumContent($userId, $albumName)
{
   $url = 'http://picasaweb.google.com/data/feed/api/user/' .
     urlencode($userId) . '/album/' . urlencode($albumName);

   $xml = file_get_contents($url); // a workaround needed on my server
   $xml = str_replace("xmlns='http://www.w3.org/2005/Atom'", '', $xml);

   $dom = new domdocument;
   $dom->loadXml($xml);

   $xpath = new domxpath($dom);
   $nodes = $xpath->query('//entry');
   foreach ($nodes as $node) {
    echo '<p>';
    $imageUrl = $xpath->query('.//media:thumbnail/@url', $node)->item(0)->textContent;
    $keywords = $xpath->query('.//media:keywords', $node)->item(0)->firstChild->data;
    echo '<img src="' . htmlentities($imageUrl) . '" alt="" />';
    echo '<br />Tags: <em>' . htmlentities($keywords) . '</em>';
    echo '</p>';
   }
}


Image editor Picnik, which needs Flash 9, is a (very cool) third-party sample application making use of this API already. The problem? To connect to your Picasa album, Picnik requires you to enter your Google Account login & password. There's no way I'll do that on a non-Google domain (outside of Orkut, I guess, but even at Orkut the login Iframe is hosted at Google.com). A better way to implement this might be to forward to a Google.com page - one that promises your credentials won't be shared with the site - which then only passes back a token to the application.

[Hat tip to Zmarties and Google Code Blog!]

Comments

About the Author:
Philipp Lenssen from Germany, author of 55 Ways to Have Fun With Google, shares his views & news on the search industry in the daily Google Blogoscoped.



Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact | Site Map

DevWebProSE is an iEntry, Inc.® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal