Lightweight PHP Picasa API

I needed a lightweight PHP library to pull images and image data from a public Google Picasa gallery. The result is a PHP class, based on this work, which was then used as a foundation for a PmWiki cookbook pmGallery. PmGallery allows you to pull Picasa based images from public albums into PmWiki, using a simple markup.

If you want full access to Picasa's API you have a choice of client-side libraries, including one for PHP, using the Zend framework. The library itself is pretty big weighing in at 1.5Mb.


Download v0.2.0
The API comes in two files -- this is for future features. The library uses the PHP function simplexml_load_string, so it will only work under PHP5. Save both files in the same directory.

  • feeder.php: provides a utility to read and cache feeds
  • picasa.php5: the main Picasa API library

You'll also need to create a directory "cache/" in the same location that you store feeder.php. Set permissions on the "cache/" directory to 755.

Using the Library

You'll need to first include picasa.php5, then instantiate a new picasaAPI() object, and finally set various options:

$myPicasaParser = new picasaAPI();
$myPicasaParser->updateOption('tag', 'cars,trucks');
$myPicasaParser->updateOption('user', 'USER_NAME');

Other options you can set are:

  • startimg: number indicating the starting image. Used for paging through large numbers of items to include in the returned feed.
  • tag: Comma separated list of tags to be matched. Images must match ALL tags to be included.
  • user: Name of the users Picasa account.
  • thumbsize (72): Size of the thumbnail: 32, 48, 64, 72, 144, 160,200, 288, 320, 400, 512, 576, 640, 720, 800
  • imagesize (640): Size of the image: 32, 48, 64, 72, 144, 160,200, 288, 320, 400, 512, 576, 640, 720, 800
  • maxresults (50): The maximum number of items to include in the feed.
  • urlbase (com): Determines the country used as the source of the feed (i.e., 'de', '', etc.).
  • cachelife (7200): Number of seconds that the feed is cached. Set to 0 to disable caching.
  • cachedir (cache/): Location of the cache directory. Default is a directory named "cache" in the location of feeder.php.
  • proxy: name and port of a proxy (if required).

Next, get a feed link (based on the options used above), and parse the feed:

$feedUrl = $myPicasaParser->createFeedUrl('ALBUM', false);
$picasa = $myPicasaParser->parseFeed( $feedUrl );

And finally, access elements corresponding to four namespaces:

for ($i=0; $i < count($picasa['main']); $i++){

   $image = $picasa['main'][$i];
   $entry = $picasa['entry'][$i];
   $gphoto = $picasa['gphoto'][$i];
   $exif = $picasa['exif'][$i];



Take a look in picasa.php5 to see what elements are available within each namespace.


Picasa provides atom feeds of public albums and images. There are two basic feeds, one for albums, and one for images:

Caching the Feed

feeder.php is responsible for actually getting the feed from Picasa. Each unique feed is cached for a default of 7,200 seconds (2 hours). That prevents hitting Picasa too often, for feeds which probably don't change that often. Old entries in the cache are cleaned out as they need to be replaced by newer feeds.

Parsing XML

Once we have the feed stored, we can use PHP's built-in XML parser simplexml_load_string:

$feed = simplexml_load_string($feedXml);
$namespace = $feed->getDocNamespaces();

We should then be able to iterate through each element of the $feed array. Things aren't quite that easy though, as Atom feeds use XML namespaces. These are documented over on the Picasa API Reference -- have fun with that.

The entry and exif namespaces are two of the trickier elements to access. From picasa.php5:

$con_attr = $ns_media->group->content->attributes();
$feed_arr['entry'][$i]['url'] = (string)$con_attr['url'];
$feed_arr['entry'][$i]['width'] = (string)$con_attr['width'];

The key here is that the Picasa feed returns an HTML tag. The "attributes()" call parses each element of the tag, so we have access to the URL, width, height.

And on the exif namespace:

$feed_arr['exif'][$i]['distance'] = (string)$exif->distance;

Here the exif data is stored within an elements called "tags". Go figure.

So in conclusion...

If you made it all the way down here, then congratulations. If you're stuck or you want to change the library to include additional elements, then the first thing to do is to take a look at the feed -- either the cached version, or simply enter the feed URL into the browser. That'll help you find the elements you need.

If you're trying to find EXIF data, and your feed relies on tags, then welcome to Google bug-land -- you can't. Feel free to vote for this bug.

And lastly, as a final suicidal stab, Picasa make it impossible to generate RSS feeds, as their feeds are ordered in reverse chronological order -- and there is no option to change it. Here's the bug-fix request -- vote away.


  1. By Cameron, on March 19, 2009, at 12:06 PM
    Cool, I didn't know someone else made a PHP Picasa API until someone emailed it to me. Was it coincidence that your project name is exactly the same as mine? : ) Well I haven't implemented caching so nice work. Oh btw you can work around the feed ordering issue by adding the q parameter in the feed (even if you're not doing a keyword search). That bug is a killer for RSS feeds for sure. Anyway...looks great!
  2. By David Gilbert, on March 19, 2009, at 06:49 PM
    Cameron: Not really sure the API really had a name, I just stuck some keywords there -- so yep, guess great minds think alike : )

    And yes, the q= parameter works -- I've been using that with pretty good results. What's amazing though is the apparent lack of any kind of response from the Picasa team -- not something you tend to associate with the Google-plex.
  3. By Chris, on April 07, 2009, at 09:08 PM

    I wrote a script about a year and a half ago that would parse a user's public feed, and make an xml file for a flash slideshow (Slide Show Pro). At the time, I used SimplePie to help me parse the feed because my experience with xml was limited.

    It worked fine, and using someone's username as an input, it created a gallery with all public albums and images with descriptions, etc. However, it seems to break down with a large amount of albums, 50+, timing out the script. I figured using php5's built-in xml functions would be faster, so a google search landed me here!

    I'm having trouble actually using the class you've created. Can you perhaps include a sample php file that would say... print out on the page each album name and that album's image titles? Or just some kind of example to show how you output or use some of the attributes from the feeds? That would be very helpful to me.

    Thank you.
  4. By David Gilbert, on April 08, 2009, at 06:55 PM
    Take a look at feeder.php, that's the file that actually uses the feed -- that should get you started. You can see the XML structure of the feed by visiting the actual URL -- add some echo statements in the picasa5.php->createFeedUrl() function to find the URL. Or use this one:

    I also seem to recall there is a maximum limit of 50 albums that can be retrieved, so maybe you're running into that limit?
  5. By Rain, on June 01, 2010, at 10:08 PM
    Thanks for information. It is of great help. here I've found an overview of the Picasa Web Albums Data API. There re some interesting moments.
  6. By David Gilbert, on June 02, 2010, at 10:11 PM
    The video provides a pretty basic overview of the API. What we really need is for them to fix the bug (or documentation) that prevents sorting through the API, and means that RSS-type feeds are non-functional.