Now Available, Picasa API Version 3.2

Sunday, January 25, 2009 at 2:39 PM
It's been a while since the last update to my Lightweight PHP Picasa API but the project is alive and well. It's been a busy year, what with getting married and all, but I've finally got enough additions and fixes to the previous version that it deserves a new version number. Click here to download the latest version and read below to find out what's new and exciting about it.

Thanks to everyone who has contributed to the bug fix and feature request list. I've managed to address every issue on the list except one enhancement, issue 6. Here's a rundown of the important updates:
  • Improved thumbnail access with the Picasa_Thumbnail class
  • Added Previous and Next link to Picasa_Image class
  • Added logging with Picasa_Logger class
  • Added Copy Album and Copy Image utility
For a full list of what has changed, take a look at the bug fix and feature list. The Documentation is all up to date but I'll go into further detail on the ones I mentioned.

Updated Thumbnail Access


Up until this point, there have been two ways to access thumbnails of your images, either through getSmallThumb(), getMediumThumb() and getLargeThumb(), or through getThumbUrlMap() and getThumbHeightMap(). The first only allowed access to three thumbnail sizes at a time and the other was just plain clunky and awkward. I originally thought giving thumbnails their own class was overkill because there's really only three fields, but after working with the two current methods I decided a Thumbnail class is necessary. The original methods will still always be supported.

Whatever thumbnails you request of an image will be attached to the Picasa_Image object in the form of an array of Picasa_Thumbnail classes. Get the array by calling Picasa_Image.getThumbnails(). Once you have the array, you can access the height, width, and URL of any of the thumbnails through the getter methods. Keep in mind that even if you only request one thumbnail, you'll still get an array back from getThumbnails() and if you don't request any thumbnails, the default is to get three thumbnails.

Added Previous and Next Links


There wasn't a pretty way to do this because no information about the current query that the image came from is included in the image's XML. However, to make client code cleaner, I've added a $next and $previous var to the Image class. When getNext() or getPrevious() is called on an Image and the image doesn't already have a previous or next link, it will load both the previous and next image by loading all images in the album and cycling through them. Your code will be cleaner at least.

Added A Logging Mechanism


When someone emails me with a problem or question, I often ask them to go into the API to find out what URL is being used or what XML is being returned, etc. This can be intimidating. Hopefully from now on it will be less intimidating with the addition of the Picasa_Logger class. It's a very rudimentary logging mechanism but it will suffice for most everyone's needs.

To enable logging, just call Picasa_Logger.setEnabled(true) anywhere in your client code. By default, there is a lot of information in the API that is logged, so you can also call Picasa_Logger.setEnabled(false) if you want to disable logging later on in your script. I've implemented a Singleton pattern to make logging as simple as possible. If you'd like to log something in your client code, just write this line:

Picasa_Logger::getLogger()->logIfEnabled("This is my statement.");

This will print "This is my statement." to the screen. Unfortunately there are not different levels of logging, it's just On or Off, so as soon as you turn it on you get everything printed. Also unfortunately, you can't log to a file, only to the screen, so logging should only be turned on while you're debugging. In the future I hope to update the class to improve both of these aspects, but I didn't have the energy to do it in this version.

Copy Image and Copy Album Helper Methods

Not sure who will find this useful but you can now easily copy an image or an entire album from one account to another. You just have to have write access for the account you're copying to. The functionality comes in the Picasa class itself with the methods copyImage() and copyAlbum(). When you copy an image, all aspects of the image are copied except the comments. When you copy an album, all aspects of the album are copied, including the images! One thing to keep in mind if you do copy an album is that you have to pass in exactly the album you want to copy. You can get this by calling Picasa.getAlbumById(), but when you get the Album object from Picasa.getAlbumsByUsername(), the individual images are not included in the album objects for performance reasons. If you use this method, you'll need to call getImages() on any album you plan to copy because the images are added to the object when the getter is called.

I hope everyone finds this newest version useful, I think there are some welcomed additions. If you find any problems please feel free to add an issue. If you just want to comment on it, leave a comment here or email me. I've definitely lost some enthusiasm after spending so much time on Version 3.0 but I will post an update to this version when I find bugs with 3.2. I will also have a larger update that will include things like the upgrades I mentioned above and support for newer Picasa features like bounding box, but an update like that is a ways off. In the meantime, download the newest version here.

Comments

thanks !! very helpful post!
Posted by Anonymous on Tuesday, December 29, 2009 at 3:38 AM.
My second reply. Great API, because I can easily use it. Luckily you also wrote a post with examples.

Isn't is something to make the API website separate from your blog? In the past I also used the phpFlickr API/Class and this has his own website with documentation and examples, see: http://www.phpflickr.com/
Posted by Ruben on Sunday, March 15, 2009 at 5:33 AM.
Great to see you have created this API! Love to see you have implemented next and previous functionality.

I was searching for a solution to implement it myself, but now I am going to use your API as I find the ZEND API not easy/useful to use/implement.
Posted by Ruben on Thursday, March 12, 2009 at 2:58 PM.
Thanks, Robert, glad you're liking it. For more tutorial-type stuff, check out the original post for Version 3.0 of the API. There's a whole section on authentication and getting private albums.
Posted by Cameron on Friday, February 27, 2009 at 8:26 AM.
Hi Cameron! This seems to be just what I need right now. Have spent too many hours trying to get the full-image-URL from Google's album XML to work.

One question though. Is there a way to get private albums, the ones with an authkey? I didn't find any info on that.
Posted by Robert Wictorzon on Friday, February 27, 2009 at 2:19 AM.
Great Cameron!! This update gives a fresh breath to your project. I'll update the code in my site as soon as I can.
Posted by Bleyder on Tuesday, February 17, 2009 at 6:06 AM.
This is excellent!

Thank you!

I enjoyed the sample application code for the image/album display.

It would be great to have similar sample code for an album administration app...to showcase some of the methods and tools for managing user albums, performing auth, etc.

Thanks for making this, it's excellent and way more user friendly than the Zend_Gdata library.
Posted by jcorry on Friday, February 6, 2009 at 6:14 AM.