Google Blogoscoped

Thursday, March 22, 2007

Google’s New Picasa API

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!]

Advertisement

 
Blog  |  Forum     more >> Archive | Feed | Google's blogs | About
Advertisement

 

This site unofficially covers Google™ and more with some rights reserved. Join our forum!