Gold Plated Blog Posts
Whatev.
Thursday, December 17, 2009

Comment Moderation Through the Picasa Tools Suite


If anyone has ever read about my innovative commenting setup, you can probably guess that it results in one thing: a lot of random spammy comments. It also results in people who wouldn't normally comment on my photos doing so, which is what I built it for so it's a success in that sense. Still, cluttering the image pages with gibberish or inappropriate comments isn't good for the user experience. Unfortunately, the only way to monitor the situation is to periodically view every image in my account...until now!

Introducing Picasa Comment Moderation. With this tool, any Picasa user has the ability to view and delete comments in their Picasa account with the click of a button. The comments are sorted by the date and time they were posted and you have the option of viewing between 5 and 50 comments at a time. The image, image title, and coment author are displayed on the screen for your reference, as well as a link to the image on Picasa's website. You can even hover over the image to see the description if you're not quite sure what you're looking at.

You may notice that when you hit the link to go to the Comment Moderation tool, you're actually taken to the front page of the Picasa Tools Suite. This is for two reasons. The first is that Google requires one single exit point for any site requesting access to a user's Picasa account, so it was impossible to make a page dedicated to Comment Moderation when I already had the Picasa Image Name Updater. Secondly, doesn't two tools constitute a suite?! Well maybe not. If you have an idea for another tool I can create, please let me know so that I can truly make it a legitimate suite.

As always, the Picasa Comment Moderation tool was created with the Lightweight PHP Picasa API. Using the API proved very easy in enabling me to display and delete comments. In fact, the entire project only took around six hours to write. Now go use it! And if you have any comments/suggestions/bugs, send them my way.

Monday, June 15, 2009

Change Your Picasa Image Titles

I've had a problem since I created the Pictures section of my website and that is that my individual image pages are not included in my site's Page Count according to Google (see what I mean). This is a problem since I have a few thousand images and they would greatly increase the number of pages on the site. I figured that since I have unique content on each one (the image description and any comments entered), they should count. I brought this up to an SEO-specialist friend of mine and the first thing he pointed out is that the page titles are virtually identical across a single album. This is because I use the image title according to Picasa, which is the filename when I uploaded it to Picasa, which is whatever my camera named it or whatever generic name I came up with when I imported them from the camera. I couldn't think of anything better to use for the title and unfortunately Picasa does not offer an easy way to change the image titles.

The answer to my problem is the Picasa Image Name Updater by yours truly, Cameron Hinkle. Harnessing the power of my Lightweight PHP Picasa API, I whipped up this handy little app in just about 12 hours. Now I can update images in my Picasa account at my every whim- and you can too! I created it using AuthSub, which means you sign in to your account on Google's site and then just grant access to my app. You then type in the account you want to update, select an album, and start updating image names! I tried to model the interface after Picasa's web interface for entering captions, although I'm not a Javascript programmer so I didn't use any AJAX.

This was a great exercise in eating my own dog food. I was happy to find that things went relatively smoothly and I was able to do all the backend programming in about seven hours, which is pretty solid given the complexity (yes, that means the style took me 5 hours...I'm so bad with CSS it isn't funny). If you want to have nice-looking image titles on your account, try it yourself and feel free to leave any feedback you have here. I'd love to know what people think.

Comments

Cameron said...

I'm glad people like the ability to change image titles as well as the API itself.

As far as getting comments for just one user, I was curious myself so I looked in the documentation and here's what I found:

"To get comments specific to an image, use getImageById() and call Picasa_Image::getComments() on the returned object."

So you can't grab the comments directly, but I don't think grabbing the image is too much overhead. What do you think?

Posted Thursday, October 8, 2009 at 3:35 PM.
Paul said...

Hi,

Just out of curiosity, does your api have any way of accessing the comments of one particular photo (by photoid, for example)? From looking at the documentation, it seems that comments can currently only be retrieved by album or id. Great work, anyway.

Posted Thursday, October 8, 2009 at 10:39 AM.
Paul said...

Hi there,

I wasn't sure where to post this comment but just wanted to say I'm loving your api. I just ran a test comparing the zend framework and your api, retrieving an album containing 400 images. Your api consumed 14mb of system memory (according to php's memory_get_usage function). Meanwhile, the zend framework consumed 64mb - 4.5 times more than your api! Good work man... hope you keep it up.

Posted Thursday, October 1, 2009 at 5:26 AM.
Ruben said...

Nice work! Just tested is on one of my albums and it is working perfect.

Posted Monday, June 22, 2009 at 12:56 PM.
Wednesday, May 20, 2009

Picasa Version 3.3, Now With Server-Side Caching

The Lightweight PHP Picasa API bug list is finally empty and that can only mean one thing, a shiny new version! Four months have passed since the last version and it's time for another iteration. Aside from one big new feature, this version largely fixes a series of small bugs. Here are the high points:

  • Implemented Server-Side Caching (Issue 6)
  • Fixed bug in Picasa.getImages() where keywords couldn't be searched when ordering the feed (Issue 15)
  • Added "weblink" field to Accounts, Albums, and Images (Issue 17)
  • Added Bounding Box search for images (Issue 18)
  • Modified Exception classes to print a stack trace when thrown (Issue 19)
If these sound like additions you'd like to see in your code, download it now. In fact, you'll probably find a few extra goodies too insignificant to mention (or that were never documented). As always, it's all backwards-compatible with previous versions of the API. The Documentation has also been updated, so take a look. Here I'll go into the specifics of each addition.

Implemented Server-Side Caching

This had been a feature request for a long time and I always thought it would be too difficult to implement but I finally realized it could actually be very simple. The Picasa Data API that the PHP API is powered by just uses XML documents to transport information about a Picasa account. My API simply parses those documents and puts the information into PHP objects. The solution to implement caching was very obvious, I just store those XML documents on the server and check to see if they exist before asking Google for them. This was all very easy, in fact, and the difficult part was making sure it worked securley (ie; you probably don't want to cache Private feeds) and was user-friendly.

Before I dive in to the nitty-gritty, here's the good news about caching: it's all implemented for you in Picasa.php. As long as you're not creating other objects on your own, you shouldn't need to think about it. In case you do, I'll go a bit more into detail.

The cached documents are stored, by default, in your include path, in a directory called "picasa-api-cache". I store them in the include path to make sure PHP has access to them. If the directory doesn't exist, the API attempts to create it. If it succeeds, caching is enabled immediately. If it fails, Caching is turned off and you'll never hear about it again. To see if Caching is working, visit some of your pages that access an Account, Album, or Image, then go to the root of your include path and check for the directory "picasa-api-cache". If it's there, look inside and see if there are any files there. The files look like a URL with all the slashes and question marks replaced by dots. If the directory doesn't exist or its emtpy, caching is probably not working. The easiest way to troubleshoot it is to turn Logging on somewhere in your code, which is done with he following statement (you'll remember this from Version 3.2):

Picasa_Logger:getLogger()->setEnabled(true);

You should then see logging statements telling you what is wrong with Caching. The most likely causes are:
  • PHP doesn't have access to create the "picasa-api-cache" directory. In this case you should create it yourself.
  • PHP doesn't have write access inside the picasa-api-cache" directory. In this case you should change the permissions on the directory.
If one of these is not the problem and you can't figure it out yourself, feel free to email me. Again, if Caching is not working correctly, the worst thing that will happen is that your XML files will be requested from Picasa every time, which is not such a bad thing (in fact, it's exactly how the API has worked up until this release).

Just like the Logging class introduced in Version 3.2, the Cache class is created as a Singleton. So whenever you want to access the cache (which you may never need to do in your client code), you just call Picasa_Cache::getCache() and you'll have the Cache object. You can then call any of the public methods inside the Picasa_Cache class. For instance, you can disable caching, set the path that cached files are stored at, and set the amount of time before cached files expire in your client code (set to two hours by default). At the top of any PHP page that uses the API, you would call the setter for the field you want to modify. If you don't want to remember to do that in your code, you can go into the API and modify it directly. To do this, go to Picasa/Cache.php and update the static private members defined at the top of the class. The cache path is always created inside the include path so if you want to change that behavior, you'll need to update the constructor method inside Picasa_Cache, which is very easy to do.

The last thing to know about the Cache is the way it's implemented in Picasa.php. Basically all the methods that get Accounts, Albums, Images, ImageCollections, Tags, Comments, or Authors all implement caching. For methods retrieving a list based on a set of criteria, the feed is always cached when the visibility is set to "public" (which is the default). This so you don't go in as an authorized user, cache a bunch of private albums and then when an unauthorized user requests the albums, they get the private ones as well as public ones. For the Picasa methods where visibility is not a search criteria, the feed is always cached when the Picasa::$auth member is null. If you don't authenticate the instance of Picasa you're using, it will always be null. If you have authenticated it and you want to utilize the cache in such a call you can either call Picasa::clearAuthentication() or if you'd rather not throw away your auth, just instantiate a new Picasa instance, don't authenticate it, and use that to fetch the album.

Fixed Bug in Keyword Search

Due to a bug in the Picasa data api itself that doesn't allow ordering of images in an image search by upload date, I was forced to introduce a work-around in version 3.2. When I implemented this, I did it a little sloppily and killed keyword searching (thanks to Google Code user Gaitan for finding this and reporting it). This was an oversight and a quick fix. Search away!

Added Weblink Field


Special thanks to Picasa API user Ruben Woudsma who noticed the usefulness of having a link back to the Picasaweb page for an image. In fact, he wrote the code to add it himself and sent it to me. Open Source programming at it's best. Anyway, you can now call getWeblink() on a Picasa_Account, Picasa_Album, or Picasa_Image object and it will give you the URL to that object on the Picasaweb site.

Added Bounding-Box Search

This was relatively straight-forward, Google introduced searching by Geo-coordinates and I just added it to the API. You can pass 4 bounding-box coordinates to Picasa->getImages() in the $boundingBox parameter and you will get back images within those coordinates. It should be a single string with four coordinates seperated by commas.

Modified Exception Class

I have to plead ignorance on this one, I had no idea PHP was so self-aware! Now when an exception is thrown, a stack trace is printed. This was simple to do using PHP's built-in getTrace() method.

That about sums up the bulk of the changes for this round. If you find something not working, kindly enter a bug and it will get addressed. If you have a question, first take a look at the documentation and if you're still stumped, email me. And if you don't yet have the latest version, go get it!

Comments

Guardian said...

Thanks for this API, I wish there was somewhere for developers to share their usage code for those that are less experienced with PHP.
I'm using this API to create a module for a content management system and had it up and running in a few hours including a custom stylesheet for presentation of the images etc.

Google does proved an 'embed' feature to enable galleries of images, it would be pretty nice to see some example code for that or include something in the API so you could do something like getEmbed->albumid()

Posted Monday, November 23, 2009 at 5:06 AM.
Marcin G. said...

Hi, first of all - your Picasa Api is great ;-) I was getting some errors while trying to get private albums, but it was my php x64 problem, after going back to x86 they're gone.

But now i have another issue - while trying to postAlbum i get in response error 400 - Content is not allowed in prolog. What can be the problem?

raw data from wireshark:
http://www.wklej.eu/index.php?id=732cd71208
(of course the real token is different)

getting private albums and images is working fine.

Posted Saturday, October 3, 2009 at 1:46 PM.
Anonymous said...

Hi there, first of all - great work you're doing... it's very useful. Just a quick question, does your API enable re-ordering of images within an album? If not, that would be very handy! Cheers.

Posted Wednesday, September 30, 2009 at 6:06 AM.
finster said...

Great piece of software.

Is there an easy way to display the image at a larger size than using $image->getLargeThumb() ?

I'm hoping I've missed something obvious!

Thanks

Posted Friday, September 11, 2009 at 9:22 AM.
boredom2 said...

This is really great work!
Are you planning to support "secure authorization" using AuthSub in order to remove the annoying hint of google within the access window?

Thank you very much,
Christoph
Germany

Posted Friday, September 4, 2009 at 4:34 AM.
Cameron said...

Well I'm glad everyone is liking the new version. And mr.bmc, I took your advice and added the project to SVN via Google Code. You may now go to the Google Code site and checkout the latest version.

Not having this project under version control was my dirty little secret! I know, I know, what would Joel say? :P

Posted Friday, June 26, 2009 at 9:18 PM.
Cay said...

Awesome work dude, I had this working in 3 hours:
http://www.reposteria.cl/fotos.php
:D
Thanks!

Posted Friday, June 26, 2009 at 5:14 PM.
Bleyder said...

Great work Cameron!!

Posted Thursday, June 25, 2009 at 2:09 AM.
mr.bmc said...

Sweet. Your class beats up Zend and takes its lunch money.

Posted Tuesday, June 23, 2009 at 6:48 AM.
Cameron said...

Yeah that is a great idea. I will work on that and update here when it's available.

Posted Monday, June 22, 2009 at 10:20 PM.
mr.bmc said...

Do you have plans to allow SVN access via Google Code?

http://picasaphp.googlecode.com/svn/trunk/

Posted Monday, June 22, 2009 at 12:55 PM.
Cameron said...

Day Two of the API's latest release and already a critical bug! You may have noticed the cache folder gets created one level above your include path if your include path doesn't have a slash at the end (Issue 20). Well I've fixed it and uploaded the new version so if you downloaded it since the release you'll probably want to do it again, or just make sure your include path has a slash at the end. Oh and my QA staff have all been fired!

Posted Tuesday, June 9, 2009 at 8:20 PM.
Sunday, January 25, 2009

Now Available, Picasa API Version 3.2

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

Anonymous said...

thanks !! very helpful post!

Posted Tuesday, December 29, 2009 at 3:38 AM.
Ruben said...

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 Sunday, March 15, 2009 at 5:33 AM.
Ruben said...

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 Thursday, March 12, 2009 at 2:58 PM.
Cameron said...

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 Friday, February 27, 2009 at 8:26 AM.
Robert Wictorzon said...

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 Friday, February 27, 2009 at 2:19 AM.
Bleyder said...

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 Tuesday, February 17, 2009 at 6:06 AM.
jcorry said...

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 Friday, February 6, 2009 at 6:14 AM.
Tuesday, October 21, 2008

New to the Pictures Section

This is kind of a two-part post. The first is to just let everyone know that I've finally uploaded pictures of the Portland wedding that my Uncle Steve took. If you were at the wedding, there's a good chance you'll find yourself in one and if you weren't, check it out to see what you missed!

If you've ever used the commenting option at the bottom of each picture, you'll also notice a few new features. I'm sure you know how frustrating it is when you don't enter your name and it inserts "Some anonymous shmoe" as a replacement. My first new feature alleviates that problem to a large extent. Now the first time you enter a comment on a computer, it will remember your name and if you forget to enter your name in a future comment, it will insert the name you used in your last comment. It won't follow you around from computer to computer (that would be impossible) but it will work on any computer you use as long as you don't clear your cookies.

If you like to comment on photos you probably know the feeling you get when you accidentally hit the Enter button after leaving half a comment, or the feeling you get when you leave comments after heavily drinking the night before and wake up to find yourself the laughing stock of the community (the cameronhinkle.com community, that is. ....so basically, me). At your rescue is the new "delete" button. It's in the form of a red X and it will appear at the end of all your future comments. Again, it only works per-computer and will be there as long as you don't clear your cookies. If you don't know what "clear your cookies" means, you'll have some catching up to do. I would start here.

For those of you who care, I'll get a little into the specifics of how I made these possible. The first is easy, I just set a cookie in your browser that contains the name you enter for each comment, then I check for it if you don't enter a name in the future. The delete button is a little tougher. Cameronhinkle.com now keeps a cookie in your browser that holds a pipe-delimited list of comments that you've made. Every time you enter a new comment, it adds the comment id to the cookie. Then whenever you view a picture on CameronHinkle.com, it explodes the list of comment ids into an array and iterates through each comment id to see if it exists in the array of comments that have been submitted for that photo. If a comment is found in the array, it puts the red X inside a form at the end of that comment with the comment id as a hidden field. When the X is clicked, the form posts the comment id to the server and the comment is deleted using my versatile and robust Picasa API. The way that it is deleted is similar to the way it's posted, which you can read about in my article Comments: Enabled. I haven't worked out all the kinks (in fact it just blew up on me a second ago) but it's coming along nicely and I think it will be a really useful addition.

This deleting mechanism obviously opens up a bit of a security risk. All someone would have to do is post a comment id to the page to delete any comment they want. I'm not too concerned about this because I don't know who would care about deleting comments. Also, it would be a little bit of a hassle to find the comment id for a particular comment, especially if you don't know anything about the Picasa API. If I put the X next to every single comment I could definitely see someone clicking all the X's just to be annoying, but it's probably inconvenient enough as it is that no one will bother. If I'm wrong and there is an incident, I'll just encrypt the ids before I store them in the cookie. I would do that now but I wanted to make the page load as fast as possible.

Hopefully this and the Comments: Enabled post has given some people a few creative ideas of what is possible with the API. I've gotten a lot of good feedback on the Pictures section in general and am always trying to come up with ways to improve it. Of course if you don't use it then all my work is in vain, so go comment find your favorite picture and make some comments!

Wednesday, April 23, 2008

Picasa API Update

I've been pretty lax in getting an update to the Picasa API available for download. I've got a bit more going on than usual, and everyone can probably expect this level of commitment through the NBA Playoffs :) However I did finally manage to get back in and write some code. The outcome is Version 3.1 of the Picasa API, which you can download here. All the other download links on the site are up to date as well. This update fixes the following problem:

Getting back into the API code, I've had a few good ideas for enhancements, now I just have to force myself to implement them. I'm still getting good feedback and please continue to send in your comments. Unfortunately I haven't been able to post any more code samples but I've been answering specific questions by email as they come in so if you have questions, let me know.

Comments

Cameron said...

Glad you like it! Well officially I have not stopped development. However, life has been particularly bigger this summer with two weddings and a honeymoon so I haven't had much time at all to work on the API. I do fully intend on putting out an update in October and I'll be sure to make a post the minute I do

Oh and to the other comment, if you'd like an example the best post to look at is http://cameronhinkle.com/blog/id/7309305433109234799.

Posted Saturday, October 11, 2008 at 3:55 PM.
Bleyder said...

Great Picasa Class!!. I'll use it in my site.

Are you going to improve this code or you have stopped its development?

Good Luck!!

Posted Friday, September 19, 2008 at 2:27 AM.
Rainer said...

Hi,

your Picasa API is very nice. Can you give me some example files for better understanding, please. That would be very nice.

Sorry for my bad English. I am from Germany and English isn't my language.

Thanks

Rainer

Posted Wednesday, May 21, 2008 at 1:10 PM.
Sunday, April 13, 2008

Building Your Own Picasa Gallery

Since the release of version 3 of my Picasa API I've received some feedback from users that it would be helpful to have some sample code for those who want to do the basics: host their own gallery. I can relate with this, since it's the reason I built the API in the first place. Sure, you can do a lot of other cool stuff with the API, like uploading and managing photos, but certainly the typical adopter is just going to want their own Picasa pictures viewable from their personal homepage. So here is a quick rundown of how to do a basic gallery using the Lightweight PHP Picasa API, version 3.0.

As you might already know, my gallery consists of three types of pages, which I will refer to as an account page (seen here), an album page (for instance, here), and an image page (for instance, over here). It's pretty self explanatory, the account page lists all the albums, the album page lists all the photos in an album, the image page shows a larger version of the selected image. For each page type, you'll need some kind of information that you can store in a constant or get from GET/POST data. I'll go over each page type and list source code along with what information is required.

Account Page
For the account page, the only thing you'll need is the username. I recommend storing the username in a constant variable somewhere where all your code can access. This is so that if your username changes, or you want to give your code to someone else, you only have to change the username in one place. I store mine in a variable called "Cam_Util_PictureUtil::$USERNAME". However, for the sake of readability, I'll just refer to it in the following code as "$username". Here's the code for the account page, which just outputs each album's icon with a link to the album page. I use a URL structure similar to what my site uses, but modified to be closer to the typical setup. And obviously you can change the HTML to suit your needs:

$pic = new Picasa();
$account = $pic->getAlbumsByUsername($username);
$albums = $account->getAlbums();
foreach ($albums as $album) {
print('<a href="http://www.your_web_site.com/album.php?
albumid='.$album->getIdnum().'">
<img src="'.$album->getIcon().'" />');
print('<div>'.$album->getTitle().'</div>');
}


Album Page
For the album page, you'll not only need the username, but you'll also need the album id. If you use the URL structure used in the previous example, you should be able to get the album id from the $_GET superglobal. I'll include how to do that in the code sample. So the album page just prints each image in the album with a link to the Image Page and the album title displayed below:
$albumid = $_GET["albumid"];
$pic = new Picasa();
$album = $pic->getAlbumById($username, $albumid);
$images = $album->getImages();
foreach ($images as $image) {
print('<a href="http://www.your_web_site.com/image.php?
albumid='.$albumid.'&imageid='.$image->getIdnum().'">
<img src="'.$image->getMediumThumb().'"/>');
print('<div>'.$image->getTitle().'</div>');
}

Image Page
Lastly for the image page, as you might have guessed, you'll need the username, album id, and image id. Again, using the above example, you get the image id from the $_GET superglobal. The image page prints the image, the image title, and the description of the image:
$albumid = $_GET["albumid"];
$imageid = $_GET["imageid"];
$pic = new Picasa();
$image = $pic->getImageById($username,$albumid, $imageid);
print ('<img src="$image->getLargeThumb().'" />');
print('<div>'.$image->getTitle());
print('<div>'.$image->getDescription().'</div></div>');

Unfortunately the current implementation of Picasa::getImageById() doesn't support any image sizes other than the defaults (which are pretty small). This was an oversight on my part because there was a workaround that made it not necessary. Unfortunately, due to a change in Google's API, the workaround no longer actually works. I've emailed the Picasa development mailing list to find out if there is another workaround that will work now, but I've also entered an enhancement request in my project's Google Code page. As soon as I fulfill that request, I'll post a quick tutorial on how to get larger sized images. It should be less than a week for that to happen.

Hopefully this tutorial has been helpful. Thanks to everyone who has given me feedback on the API, so far I've only heard good things. If something's not quite working right or it seems there's something wrong with the tutorial here, please let me know. And check back in the next week, I should have the fix for getting larger image sizes available for download, and I'll include a bit of code on displaying and posting comments for your images.

Comments

Sidd said...

It is a nice API and nice tutorial too.
It helped me a lot to figure out what I want in photoclub. Thank you a lot.

Posted Sunday, August 30, 2009 at 11:24 AM.
Gerald said...

Quick reply!
You were right. By default I was setup to run php 4. It was easily fixed. Thanks.

Posted Tuesday, August 11, 2009 at 10:12 AM.
Cameron said...

Those errors look a lot like you're using PHP4 instead of PHP5. The other common problem people have is they do not have fopen turned on but you would probably be receiving a different error in that case. Try to find out for sure what version of PHP you're running.

Posted Sunday, August 9, 2009 at 2:53 PM.
Gerald said...

I tried using your API and got nothing but Fatal errors. I'm not sure what I did wrong. I'm an intermediate PHP developer and have a solid understanding of PHP syntax. I looked through all of your files and didn't notice anything syntactically wrong so I guess it could be something wrong with my server. I'm hosting on GoDaddy and I think they have the latest version of PHP installed, but I don't know off the top of my head.

Anyway, any assistance would be great.

Here is the code I'm using:

require_once 'Picasa.php';

$username = "erinnefullam";

$pic = new Picasa();
$account = $pic->getAlbumsByUsername($username);
$albums = $account->getAlbums();
foreach ($albums as $album) {
print('<a href="http://www.fullamphotography.com/albums.php?
albumid='.$album->getIdnum().'">
<img src="'.$album->getIcon().'" />');
print('<div>'.$album->getTitle().'</div>');
}


And the Error Message:
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/content/e/f/u/efullam/html/Picasa.php on line 63

Posted Sunday, August 9, 2009 at 2:50 PM.
Bruno said...

Thank you Cameron for sharing this.
It works great for me.

Posted Sunday, July 5, 2009 at 2:30 AM.
Bruno Simões said...

Thank you Cameron for sharing this.
It works great for me.

Posted Sunday, July 5, 2009 at 2:30 AM.
Pierre said...

Very nice api indeed!

Took me a while to understand some of it though, and I can understand that people who are not used to dive into classes could have a hard time getting things to work.

Anyway, to get the larger images (I went with 640) I did this:

$pic = new Picasa();
$username = "Your_Username";

$album = $pic->getAlbumById($username, $albumid);
$images = $album->getImages();

foreach ($images as $image) {

$imagelink = $pic->getImageById($username, $albumid, $image->getIdNum(), 640, 640);

print('<a href="'.$imagelink->getContent().'">';
print('<img src="'.$image->getMediumThumb().'"></a>';
}

Cheers! :D

Posted Sunday, April 26, 2009 at 3:57 PM.
Cameron said...

Sorry you're having trouble, Kenneth. Feel free to email me your code and I can take a look.

Posted Tuesday, April 14, 2009 at 8:44 PM.
Kenneth said...

Thanks for the sample code. But when I tried it, I am not able to make the Account Page sample to work. The getAlbums does not return the albums. The getAlbumsByUsername does work.

I am using PHP 5.16 with API 3.2

Thanks

Posted Tuesday, April 14, 2009 at 8:17 PM.
jcorry said...

I'm having trouble with authorizeWithAuthSub().

When I redirect to Google using: redirectToLoginPage(myUrl), I click 'grant access' at the Google auth page and am returned to my app.

The querystring of the URL I'm returned to has ?token=xxx, the request method is get...but somehow the $_GET array is empty.

That doesn't make any sense.

So I refresh the page manually using the same URL/querystring and get a Picasa_Exception_FailedAuthorizationException.

What's going on?

Posted Friday, February 13, 2009 at 5:30 PM.
JRC said...

Sorted! Just wanted to let you know to save the trouble of posting a reply...

For anyone else who's wondering, you can set the include path as follows:

ini_set('include_path',ini_get('include_path').'.:/home/path/to/picasa/apifolder/');

Posted Tuesday, July 8, 2008 at 1:27 AM.
Patrick said...

I talked to my hosting company, and they said fopen is off-- which I figure is probably the cause of this and other similar scripts not working for me.

They said I can use curl.

Posted Monday, July 7, 2008 at 3:02 AM.
JRC said...

Hi there

Really excited about using your api, but I just can't get it to work. I'm having the same problem as anonymous - i.e. the paths aren't working. I'm on a shared host so can't place the api within the include path (afaik) - I've tried using ini_set at the top of my page, but that's not working either - can you help?

While I'm here - thanks for your hard work on all this - just hope I can get it working at some point!

Posted Sunday, July 6, 2008 at 10:43 PM.
Cameron said...

No problem, Pat, it happens to the best of us. And again, I'm available via email if you still want to try to get it to work.

Posted Saturday, July 5, 2008 at 10:23 AM.
Patrick said...

I was obviously out of line with that comment-- and I apologize.

Posted Friday, July 4, 2008 at 6:32 PM.
Cameron said...

Hmm, I'm not sure what you're doing wrong, I haven't heard of other people having problems like that. If you want me to try to figure out where you're making mistakes, I'm pretty responsive via email.

Sorry you're getting so worked up, I can sense the frustration in your tone. But that's part of being a programmer I guess. Reminds me of a comic I saw on a coworker's wall. Haven't we all been there?

Posted Friday, July 4, 2008 at 5:28 PM.
Anonymous said...

I thought this was going to be a simple and easy solution to what I wanted to do: Display my picasa galleries on my page.

But I get nothing but errors. After spending an hour fixing your include paths(you have paths to files in different directories without the directory included in the path, and paths to files in the same directory pointing to different directories).. I thought OK now it will work.. include paths are different for everyone.

Nope.

I used your code from this page and got nothing but fatal errors. Not sure why. I can't post the code on here to show you either.

Probably should have left it with the simple version-- which I wanted to download but you changed the link for that one to this bloated and broken version.

Posted Friday, July 4, 2008 at 2:21 PM.
Wen V said...

Great work! I have been looking for this for a very long time!
It works great for me, your gallery example. The only thing is the small size if the pictures. Just letting you know that I love to hear a solution!

Posted Tuesday, July 1, 2008 at 2:17 PM.
Cameron said...

Yes, I did look into this with the Picasa mailing list. It is Picasa's policy to only allow embedded images of 800px and less. So to get a larger version of an image you would call Picasa::getImageById() and pass in a valid pixel size for either imgmax or thumbsize. Valid values are, according to the Picasa documentation:

200, 288, 320, 400, 512, 576, 640, 720, 800

For me, this is large enough. If you need a larger version you can still get it, but you won't be able to embed it in your page, you can only have the user explicitly download it to their hard drive and open it. Valid values for that are:

912, 1024, 1152, 1280, 1440, 1600

If you notice on Picasaweb, they follow the same rules. The main image is 720px and I believe the download version is 1600px. Keep in mind that these values represent the longest side of the image, not the top or side. I could update my Pictures section to use larger images but I think the default size is fine for a preview; users can click on the image for a larger one displayed via LightBox.

Unfortunately using thumbnails can be a bit of a hassle with my API (Issue 4 in the issue list). I think the current implementation was born from a 3am coding session. I'm probably going to undeprecate the fields that I previously deprecated to put in place the current system, and I'll add a new way for retrieving them. I'm not sure when I'll have time to do this, particularly with me getting married in 2 months, but I'm pretty confident I'll get back to working on the API soon. I've been working in Eclipse since starting at Nike and am looking forward to some Vim time.

Posted Sunday, June 29, 2008 at 12:08 AM.
Anonymous said...

hey,
is there anyway to see the normal size image that i would see via google's picasaweb interface? i read that you contacted google about that; just curious if any response since april? it's kind of small the current one :)
thanks,
matthew

Posted Saturday, June 28, 2008 at 11:20 PM.
Monday, April 7, 2008

Lightweight PHP Picasa API Version 3.0

After weeks and weeks of toiling away at my desk in my free time, I've finally put the finishing touches on Version 3.0 of my Lightweight PHP Picasa API. I think the extra time has not been wasted, as this version is about a thousand times more robust and feature-rich than versions 1 and 2, as well as being a lot easier to use. For easy access, here are the important links:

Download the API source code

View the Documentation

View the bug and feature request list

Here I'll list the major features, and then go into greater detail on each one. Features include:

  • Automatic query building through the Picasa class
    • Pass in the parameters for your request and the member functions will build and send the query for you.
  • Robust error handling through the Picasa_Exception class
    • 8 different Exception classes that can be caught individually, all of which extend Picasa_Exception to allow any level of granularity your situation requires.
  • Easy-to-use implementation of authorizations through the Picasa class
    • Supports Client Login or AuthSub
    • Supports persistent authorizations using browser cookies
  • Added previously unsupported operations
    • Suports not only fetching feeds, but also posting and deleting images, albums, comments, and tags, as well as updating images and albums.
    • Include access to public and private albums.
  • Added several fields to existing classes
    • Added support for Exif data, GML coordinates, among others
  • Comprehensive documentation using PHPDoc
    • View the Javadoc style manual here.
  • 100% backwards compatible with versions 1 and 2
  • It's still "lightweight"
    • No special requirements, just PHP 5
    • Less than a third the size of the Zend framework
Automatic query building through the Picasa class
The Picasa class is certainly the biggest addition to the new version. It's really the only object that your client code will ever have to instantiate. It handles both authorization as well as data requests and manipulations (posting and updating images, etc). The nice part about how it handles data requests is that you'll literally never have to formulate a query string again. Pretty much any type of feed that can be requested from Picasa is supported through just a few different methods in this class. Just instantiate a Picasa object and then call the method you're looking for. For instance, to get all albums for user "goldplateddiapers" (that's me), use the following code:
$pic = new Picasa();
$albums = $pic->getAlbumsByUsername("goldplateddiapers");
Now $albums will hold a Picasa_Account object that has an array of all my albums. To see exactly what is in a Picasa_Album, you can look at the manual, or you can just print the object. I've added very handy __toString() methods for all the objects. So add this line and see what you get:
print $albums;
If you're viewing this in Firefox (which you should be!), view the page source to get a prettier display. The output should be a nicely formatted printout of every field in the object. Each one of those fields has a getter method so that you can access the data you see.

Of course, oftentimes your request will not be as simple as getting all images from one user. So each of the "get" functions in the Picasa class take a plethora of parameters to suit your needs. For instance, take a look at the definition for Picasa::getImages():
public function getImages($username=null, $maxResults=null,
$startIndex=null, $keywords=null, $tags=null,
$visibility="public", $thumbsize=null, $imgmax=null);

As you can see, none of these parameters are required. Which ones you should supply depend on what you're looking for. To find the first 250 images in Picasa tagged "lolcats", do the following:
$pic = new Picasa();
$images = $pic->getImages(null, 250, null, null, "lolcats");
Now $images will be a Picasa_ImageCollection object with an array of up to 250 of your favorite lols. The same format follows for any methods in the API starting with "get". And of course, all of the parameters for each method are fully described in the documentation.

One thing to be careful of is that all combinations are not supported by Picasa. For instance, calling just Picasa::getImages() with no parameters, Picasa itself will probably yield an error, which will be thrown as a Picasa_Exception with the error message retrieveable through Picasa_Exception::getMessage(). See the next section for more information on exception handling. I've left it up to the client code to send acceptable requests; the API will only throw an exception if Picasa itself responds with an error, the API doesn't catch invalid combinations of parameters and thus they're not documented here. You'll have to play around with different parameter combinations or check Picasa's Developer Guide.

Robust error handling through the Picasa_Exception class
The previous versions of the API didn't do much in the way of error handling, and this aspect is probably the second biggest improvement since then. There is one main exception class, called Picasa_Exception, that all exceptions thrown from the API will be at least subclassed from. It's not an abstract class, so oftentimes an instance of Picasa_Exception itself will be thrown, but a more specific subclass will be thrown when appropriate. Take a look at the subclasses in the documentation or the source code, they're all listed in the Picasa_Exception class.

The Picasa_Exception class extends PHP's Exception class and adds a few nice fields to have. The first is Picasa_Exception::$url, which will contain the offending URL if the exception resulted in a bad request to Picasa. If the exception wasn't thrown as a result of a bad request, this field will be null. The other field that can be useful is Picasa_Exception::$response, which holds the complete response that the exception was thrown as a result of, again only if the exception is thrown because of a bad request.

To give you some background on how the API knows it should throw an exception when it's given a bad request (skip this paragraph if you don't care), basically the method that is used for executing requests (Picasa::do_request()) checks for a response of 200 or 201. If that's not found, it passes the response header to a method (Picasa::getExceptionFromInvalidPost()) that determines which kind of exception to throw. It saves the error message given by Picasa as the result of Exception->getMessage(). However, sometimes the body of the response, even if it was not a 200 or 201 response code, can be useful. For example, if a client is trying to authenticate using Client Login and Picasa requests a CAPTCHA challenge, the response code is 403, but fields are set in the body identifying the URL to the CAPTCHA challenge and the CAPTCHA's token value. The API uses the Picasa_Exception::getResponse() method to get the returned response, determine that it is a CAPTCHA challenge, and parse out the required fields.

The only other exception class in the API that adds any fields to the base Exception class is Picasa_Exception_CaptchaRequiredException. This (as you might have guessed) is thrown when a CAPTCHA challenge is requested by Picasa upon attempting to gain authorization. If you're unfamiliar with this operation, Picasa will ocassionally require a user attempting to login using Client Login to type in letters that appear in a supplied image in order to guarantee that the user is a real person. To login after a CAPTCHA is requested, you do exactly what you did to log in the first time, this time passing in the user's CAPTCHA answer and a token supplied by Picasa (see the next section for how the API deals with logins and CAPTCHAs). The Picasa_Exception_CaptchaRequiredException contains the method Picasa_Exception_CaptchaRequiredException::getCaptchaUrl() for getting the URL to the image to display, the method Picasa_Exception_CaptchaRequiredException::getCaptchaToken() for getting the token to pass along with the re-attempt at authorization, and the methods Picasa_Exception_CaptchaRequiredException::getUsername() and Picasa_Exception_CaptchaRequiredException::getPassword() for getting the user's username and password that they originally used when attempting to sign in.

As an example of how to use the Picasa_Exception classes effectively, here is an example of client code attempting to log in (see the next section for details about how to use the authorization functionality, but I think you can infer what the code is generally doing). Let's assume I've just requested the user's username and password in a form, using the POST method:
// Get the username and password from the POST superglobal
$user = $_POST['username'];
$password = $_POST['password'];

$pic = new Picasa();
try{
$pic->authorizeWithClientLogin($user, $password);
} catch (Picasa_Exception_CaptchaRequiredException $ce) {
print "Please enter the letters you see in the image: ";
print '<img src="'.$ce->getCaptchaUrl().'" />';

/* Put code for generating a form with an input field, setting $ce->getCaptchaToken(),
* $ce->getUsername(), and $cd->getPassword() as hidden fields here
*/
} catch (Picasa_Exception_InvalidUsernameOrPasswordException $ie) {
print "The username or password you have entered is invalid.";

/* Put code for handling re-logins here
*/
} catch (Picasa_Exception $e) {
print "Your attempt to login has failed: ".$e->getMessage();

/* Put code for handling relogins here
*/
}
Easy-to-use implementation of authorizations through the Picasa class
Previous implementations of the Lightweight PHP Picasa API did not support authorizations in any way. This suited my needs personally, but left a lot of people out of luck or on their own to throw something together. With the addition of the Picasa class, though, comes a suite of methods and fields for gaining and keeping authorizations. The first thing you need to know about is the difference between Client Login and AuthSub. Client Login allows you to enter a user's username and password, while AuthSub requires your client to redirect the user to a Google-hosted secure page to enter their username and password. The Picasa class supports both.

To authorize a user using Client Login:
  1. Get their username and password
  2. Call Picasa::authorizeWithClientLogin(), passing in their username and password.
At this point, if the authorization was successful, you have an "authenticated" Picasa object. Now, using this Picasa object, you can do operations that the current user is authorized to do, such as accessing their private albums, posting photos and albums to their account, etc. If the authorization was unsuccessful, a Picasa_Exception is thrown. See the previous section for instructions on how to handle such exceptions.

To authorize a user using AuthSub:
  1. Redirect the user to the Google login page using Picasa::redirectToLoginPage()
  2. On the page supplied in the $next parameter or Picasa::redirectToLoginPage(), call Picasa::authorizeWithAuthSub().

These steps automate a few things that you could also do manually, depending on what your intentions are and what your server configuration gives the API access to. First, if you want to redirect the user manually, you can call Picasa::getUrlToLoginPage() just to get the URL that you should send the user to, and then redirect them using your client code however you want. Second, if the API doesn't have access to the $_GET superglobal (which the token required for Picasa::authorizeWithAuthSub() is in), you can get the "token" parameter out of the URL however you normally would and manually pass it as the first parameter in Picasa::authorizeWithAuthSub(). If it's not passed in, or null is passed instead, the method will look in the $_GET array for the token and if it's not there, throw a Picasa_Exception_FailedAuthorizationException.

A neat feature that is built into the API is persistent login through the use of cookies. Cookies are used because there's no server-side caching mechanism supplied with the API. So by default, if you authorize a Picasa object, it will store the authorization token and the type of authorization used (AuthSub or Client Login) in the users browser cookies. Tokens don't expire for quite a while, so this allows the user to login once and remain logged in as long as you like. You can use the method Picasa::authorizeFromCookie() and it will automatically look in the user's cookies for an authorization token and authorize the object if it finds one. If it doesn't, false is returned and your client code can prompt the user to login again. So here is a snippet for logging in using AuthSub:
$pic = new Picasa();
if ($pic->authorizeFromCookie() === false) {
Picasa::redirectToLoginPage("http://yourdomain.com/samplePage.php");
}
//Perform authorized requests here

On the other hand, if you don't want the API to automatically save the token to the user's cookie and you want to save it yourself in a more secure way, you can pass false as the $saveAuthorizationToCookie parameter of either Picasa::authorizeWithAuthSub() or Picasa::authorizeWithClientLogin(). The token is returned from both methods when a successful authorization is established. To then authenticate a Picasa instance, you can either pass the token along with the type of authorization (represented by the public static members Picasa::$AUTH_TYPE_AUTH_SUB and Picasa::$AUTH_TYPE_CLIENT_LOGIN) into Picasa's constructor when you instantiate it, or call Picasa::setAuthorizationInfo(), also passing in the token and type.

It should also be noted here that Picasa actually returns a "single use token", which is only good for one request, when a user attempts to login through AuthSub. However, the API automatically converts the single use token into a session token and saves that value. There is no parameter to turn that feature off because there is no downside to doing it and a single use token is too worthless to warrant another parameter.

Added previously unsupported operations
Now that authorizations are possible, so are authorized operations. I've done my best to provide pretty much any operation available through Picasa's core Data API in this PHP version. So you can post, update, or delete albums and images from an account that you have permission to do so in once you have have an authorized Picasa instance. You can also post or delete comments and tags, and retrieve private feeds.

The methods for posting, updating, and deleting are extremely similar to the methods for retrieving feeds. There are several "posting" methods, just like there are several "getter" methods described in the first section. So let's say you want to post an album titled "Dwight Schrute's One Night Stand" to the account "goldplateddiapers":
$pic = new Picasa($token, Picasa::$AUTH_TYPE_AUTH_SUB);

if ($pic->isAuthenticated()) {
try {
$album = $pic->postAlbum("goldplateddiapers", //Username
"Dwight Schrute's One Night Stand", //Title
"Dwight and Angela exchange cat pictures.", //Summary
"private", //Access rights
"false" //Commenting enabled
);
} catch (Picasa_Exception_UnauthorizedException $ue) {
print ("You are not authorized to add this album.");
} catch (Picasa_Exception $e) {
print ("An error occured while posting the album: ".$e->getMessage());
}
} else {
Picasa::redirectToLoginPage("http://yourdomain.com/samplePage.php");
}
Yeah, I know, the parameter list gets a little ridiculous. However, I've tried to order them in such a way that they will be as short as possible. For instance, had I wanted that album to be public and allow commenting, I could have left off the last two parameters.

Now that you know how to post an album, posting images, comments, and tags are all done the exact same way, though the parameter list varies. You can also update albums and images, although Picasa doesn't allow comments or tags to be updated. Deleting is allowed for all four types of objects. Read the documentation to see exactly which parameters are accepted for each type.

Added several fields to existing classes
The most noticeable difference here is going to be in the Picasa_Image class. The amount of information that is available for each image has just about doubled. You can see that Exif data and GML information are two things that were not supported in previous versions. One thing you will have to look out for, though, is that some of the fields will be null at times. It just depends on what the Atom feed from Picasa applies. To see what fields are null while testing your client code, just print the result of Picasa::getImages() and play around with the parameter values. The __toString() method will be automatically invoked and you can get a nice view of exactly what the instantiation looks like.

There is a cool new feature for some of the getter fields, too, that alleviates some of the problem associated with the null fields. You'll notice in the past that if you request all albums for a single username, the result would have come in the form of a Picasa_Account, which would have an array of Picasa_Album objects. However, those albums would not contain any images, presumably because it would take a lot of extra time to fetch and transfer the information about each image. Now, however, the method Picasa_Album::getImages() will check to see if the $images array is null and fetch a new instance of the current image, pull out the $images array from that instance, and return it. This way, if you want the value, it will always be there. The same logic follows for Picasa_Image::getComments() and Picasa_Image::getTags().

Comprehensive documentation using PHPDoc
I've gone to great lengths to document the entire API, and I finally went through the trouble of generating the docs and hosting them. I think the documentation will be really helpful in using this API, I have literally spent hours preparing it. One thing to note is that it's split up into two packages: Picasa and Picasa_Exception; the latter can be difficult to spot from the documentation's front page, there's a link to it at the very top. You can find all the documentation here.

I did not generate documentation for the Cam folder because it is not really part of the API and shouldn't be used. I attempted to change the code inside those files to utilize the new Picasa class, but the method names and intentions didn't really make sense in the context of the new version. They're still there, for backwards compatibility sake, and they work. However, if you're a newcomer, I would certainly ignore them.

100% backwards compatible with versions 1 and 2
As with the previous versions, drop the code in where your previous code was and you should have no problem. The one caveat is that you have to have had the classes inside the Picasa folder that was provided with the old versions. That folder is no longer the topmost level, the php folder is, so be careful when doing this. And as I stated earlier, the Cam folder is included for backwards compatibility.

It's still "lightweight"
It really depends on what you call "lightweight", but I think I've held true. The main thing is that there are no special packages needed with PHP in order for it to work. It was tempting to use the cUrl library or the Http classes, but I just implemented all the HTTP responses and requests myself.

Also, it's still a very easy install. You should be able to drop the files into your include path and pretty much be ready to go right away. A lengthier explanation is given in the README, but there's not a whole lot to it other than that.

The future

Obviously I've spent a lot of time trying to make this a product that people can actually use. I didn't expect to, but it remains to be by far the most popular topic on my blog, so I decided to expand on it. To that extent, I've also opened up a Google Code page for it, which I'll mainly use for tracking issues. You can visit that here. While I can't currently see a reason to make a version 4 of the API, I will certainly have future releases. With the added functionality, there will positively come added bugs, and there are enhancements that I have thought up that I did not get time to implement. So if you find a bug, let me know or add it to the bug list, and I'll probably release an update every month or two. It also really depends on the response, whether or not people seem to like the product. Whatever happens, I'll keep all the download links pointing to the latest release, so you can be sure you're getting the most up to date code.

I made this with the intent of making it easy for PHP developers to harness the Picasa service and create really cool new products, so please do so. As always, if you have any commentary, please leave a comment here or send me an email to tell me what you think. I would love to hear that someone really likes or really dislikes anything about the API. If you have features you'd like to see, feel free to let me know or add it to the issue list. And just in case you missed it at the top:

Click here to download the API

Thanks to everyone who has helped with this and everyone who is using it. Now while the bug list is still at zero and my eyes are still open, I'm going to play my Wii...

Comments

Mindbrix said...

Hi Cameron. Nice work. The documentation is very thorough, but I couldn't find any examples, so I've created one here: https://gist.github.com/718874

The code was written for this: http://vectoria.co.uk/gallery/


Many thanks,
Nigel Barber (@mindbrix)

Posted Sunday, November 28, 2010 at 4:34 AM.
Rob said...

Hi I just tried your api, I've tried

$pic = new Picasa();
$album = $pic->getAlbumsByUsername("goldplateddiapers");
print $album;

at first it didn't display anything but when I tried to catch an exception, it throws this exception

[ TYPE: Picasa_Exception MESSAGE: An unknown error has occured. REQUESTURL: http://picasaweb.google.com/data/feed/api/user/goldplateddiapers?kind=album&access=public RESPONSEBUFFER: ] Backtrace: Picasa::getExceptionFromInvalidQuery() in \robdev\Picasa\Account.php at line 245 Picasa_Account->__construct()in \robdev\Picasa.php at line 631 Picasa->getAlbumsByUsername() in \robdev\index.php at line 6

Posted Monday, July 12, 2010 at 8:40 PM.
Cameron said...

Sandip, take a look at this documentation. The Picasa.clearAuthentication() function will clear all auth information from the Picasa object.

Posted Thursday, March 25, 2010 at 1:01 PM.
Sandip said...

Hi,

I am using this API to get the user's data. It's working fine. Thanks for providing such useful API.

I have one problem regarding the logout feature.

is it possible to logout through API?

Please reply ASAP. It's urgent.

Posted Thursday, March 25, 2010 at 5:19 AM.
gargi said...

Hi,
Please help me.. I am using the code.
The following is my code:

ini_set("include_path",$_SERVER['DOCUMENT_ROOT']."/digitalprint/api/LightweightPicasaAPIv3/");
$f = new Picasa($_GET['token'],3);
$f->convertFromSingleUseToSessionToken();
$account = $f->getAlbumsByUsername("default",null,null,"private");
$albums = $account->getAlbums();

print_r($albums);

But after authentication it displays the albums first time.

After that when I refresh the page, I am getting a blank page.

Please tell me what is the solution.

Posted Sunday, February 21, 2010 at 10:01 PM.
Vampie said...

Found it myself:

http://code.google.com/p/picasaphp/issues/detail?id=23#c1

You probably need to set allow_url_fopen to true, although I do not see it on your
php info page. That is generally the setting that people have to set.


I set it on and now it is working :-)

Just to let everybody know :-)

Posted Saturday, December 26, 2009 at 6:45 AM.
Vampie said...

Hi.

I'm trying the API, but i always get the error:

Your attempt to login has failed:

even with trying your code:
$pic = new Picasa();
$images = $pic->getImages(null, 250, null, null, "lolcats");

Any ideas?

Posted Friday, December 25, 2009 at 12:39 AM.
Guardian said...

Some users seem to have a problem with the include path thing and not all host allow you to change the servers include path via init_set. I actually changed all the 'require_once' lines so they were all including the same path but perhaps it might be easier to just do something like this as a base usage instruction;
In your base script file e.g. index.php use

define('INCLUDE_PATH','path/to/script/');
include_once INCLUDE_PATH./Picasa.php;

Then in the package files you could do something like
if(!defined(INCLUDE_PATH)) INCLUDE_PATH='';
require_once INCLUDE_PATH./packagefile.php;

Posted Sunday, November 22, 2009 at 8:46 AM.
sivanantham said...

Hi cameron,
Nice code, i am using your code and i put test page for getting albums, its returning the xml format array.
upto this i am not getting any issue, after getting that array i need to get the XML source array(i mean separated by every tags), for this you added the function in your source code or i need to add for extracting xml tags data

Posted Monday, November 16, 2009 at 6:47 AM.
Anonymous said...

Hi Cameron,

Just wanted to say thanks for your great work. I decided to check out your API because the Zend framework was eating up WAY too much memory, and after playing around with your API I've seen that it uses much less than Zend, and is easier to use also! Keep up the excellent work.

Paul.

Posted Wednesday, September 30, 2009 at 5:24 AM.
Cameron said...

Great, I'm glad you like it! By the way make sure you catch Version 3.3, which I finished a few weeks ago.

Posted Monday, June 22, 2009 at 10:18 PM.
Jeroen said...

Haha, it works!!

Thanks Cameron for investing the time in this very useful API!!

Jeroen

Posted Monday, February 2, 2009 at 1:40 PM.
Brian said...

Cameron,
Great job on the API. It is very useful and very easy to understand given the great documentation. All I wanted was to display my images from picasa on my website and your library made that easy. BTW thanks so much for the quick E-mail response, all my issues are fixed now!

Brian
brianfietsam.com

Posted Monday, October 20, 2008 at 11:32 AM.
Bicho44 said...

Hi, I cannot make to work the custom sizes
Following the example and adding the custom size at imgmax or imgthumb, always receive the SMALL version
[code]
$img = $pic->getImageById($username, $albumid, $image->getIdnum(),null,"640");
[/code]

And then at the html
[code]
echo 'a href="'.$img->getLargeThumb().'" title="'.$img->getDescription.'" class="thickbox" rel="propiedad" /';
[/code]

You can checkit at
[code]http://www.tratodirecto.com.ar/classes/picasa/index.php?albumid=5248486167921658353[/code]

Anybody can help me?

TIA

Posted Sunday, September 21, 2008 at 9:03 AM.
Xavier said...

Hi cameron!
how can I do a next/back button photo in photo page?

Posted Wednesday, September 17, 2008 at 4:52 AM.
Nikos Dimitrakopoulos said...

Oh! My best wishes and thank you again for taking the time to write this handy library :)

Posted Wednesday, September 10, 2008 at 1:04 PM.
Cameron said...

That's great, thank you! I will get that into the next version when its available for download. I've worked on it a little but unfortunately my pending nuptials have left me with absolutely no time to do anything but wedding plan (as anyone who has looked at my blog in the last two months can tell). :-/ After I get back into the normal swing of things I'll get a new version out, though. Hopefully sometime in October.

Posted Wednesday, September 10, 2008 at 12:57 PM.
Nikos Dimitrakopoulos said...

Hi there Cameron,
I was using your library (which is really useful by the way) and I found a problem.

I've already posted this in google code with a patch.

Cheers

Posted Tuesday, September 9, 2008 at 3:48 PM.
Cameron said...

Anonymous comments is something that I would really like to see as well. My workaround is pretty inventive, I think. I wrote all about it in my Comments:Enabled post. I don't think it's appropriate to add directly into the API, but using the API to implement this idea is pretty easy.

On the other hand, maybe it would be a good idea. Writing my own API is really useless unless it offers something that the "official" API doesn't (which is why the next version will have things like methods to copy an image to another album). So maybe anonymous comments wouldn't be bad to have there. I just wouldn't want Google to get after me for potentially compromising the integrity of their comments.

Hope that helps.

Posted Monday, August 11, 2008 at 1:53 PM.
Cameron said...

This comment has been removed by the author.

Posted Monday, August 11, 2008 at 1:51 PM.
Tim said...

Hi,

One thing that Google hasn't implemented yet (I guess) is the support for changing the name on a comment.
I would like to create a photo gallery where the users are able to place comments, either by entering a name or logging in to my site.
Then I would like to add a comment for them, using my own credentials, and specifying the comment authors name.

I guess this is at one hand a stupid thing to add, because you couldn't trust the name of the author anymore. However, in my case, it is stupid that you cannot alter the name.

Do you have any ideas about this, because I checked it out and your API doesn't support giving an author name either.

Greetings,

Tim

PS: Check out the current version of the photo gallery on my site (I'm sorry, but it's in Dutch.)

Posted Monday, August 11, 2008 at 1:32 PM.
John said...

I am sorry, I didn't search enough :P
Thank you, this is a great work !
John

Posted Saturday, June 7, 2008 at 6:13 AM.
Cameron said...

Hi John. I think I've already posted what you're looking for in this article. Please let me know if there is anything you have questions on that is not covered there.

Posted Friday, June 6, 2008 at 8:34 AM.
John said...

Hi Cameron,
first of all, thank you for this great work ! :)

My knowledge of php is limited, and I have problems to use your script ! :S

Could you give us some examples of scripts, like displaying albums lists, or pictures form an album ?

Thank you very much !
John

Posted Friday, June 6, 2008 at 6:11 AM.
_jas said...

thnx for your help it worked.
the problem was, the line that u said and some path problems, its working now =).

Thanks for your quick answer.

later

Julio

Posted Thursday, April 10, 2008 at 7:58 PM.
Wednesday, February 27, 2008

Comments: Enabled

Some of you may have noticed a few weeks ago that a text area for submitting comments appeared in the Pictures section of the site. Unfortunately, entering comments into the comment box would never actually produce any results. Good news! Commenting is now enabled. Feel free to browse through pictures and leave a comment if the mood strikes.

As you're posting your comments, you may find it peculiar that you don't have to sign in to anything to leave a comment and you may wonder why that is, given that Picasa does not allow anonymous comments. Well my philosophy has always been that if you have a feature that you want people to use, you should make it as easy and accessible to the user as possible. I saw having to login to your Google account as obtrusive and a barrier that would probably stop a lot of people from leaving comments. And having to leave this site for Google's login page sort of ruins the continuity of the site. I've had anonymous commenting enabled on my blog for several months now and moderating hasn't been overly time consuming, so I thought up a solution.

The solution is a big workaround and one that a lot of people probably won't be comfortable for themselves. If you'll notice when you view an image on my site (for instance), the comment author is not always the same as when you view an image directly from the PicasaWeb site (for instance). Essentially what I've done is allowed any user to post a comment on any of my photos through my own username. Once a comment is submitted, it logs the person into my Picasa account and posts the comment as though I had said it. Then to keep track of who the poster says they are, the name they entered is appended to the end of the comment, surrounded by a sequence of characters. You can see in PicasaWeb that the sequence of characters is "-={". Any time that sequence is found in a post, the text inside is stripped and set as the author. Anything after the author is discarded.

This method has a few obvious problems. First of all, PicasaWeb is going to fill up with comments posted by me and I can't really control what is posted for a time. It's not like my site gets a lot of traffic from people I don't know, though, so I think that will be fine, and I'm emailed the comments every day so that I can easily moderate them. Just to be safe, a disclaimer is tagged to the bottom of each comment, which you'll only see on the PicasaWeb site. The second problem is that this method is certainly not supported by Google. I doubt they really want me doing this, as it sort of damages the integrity of their comments and accounts. I think they likely have bigger things to worry about, but we'll see. The interesting thing is that the current version of the Google's Picasa API has a bug that will not allow a comment to be posted to an image by anyone except the owner of the Picasa account, so this is actually the only way that anyone except myself could comment on my photos through this site.

So begins the great comment experiment. It was a lot of work, but if it doesn't prove to be successful, I can always switch over to standard, authenticated commenting without too much trouble once the bug is fixed. I'm excited about this new feature and hope that it will be a way to make the site more interactive and get people more interested in seeing what new photos have been posted. Keep in mind that I finished this feature a few hours ago and I do expect some bugs (particularly if you're using Internet Explorer, but you should switch to Firefox anyway) so if it doesn't work for you, let me know and keep trying! I've done several tests and they've been successful thus far. Like I said, it was a lot of work to get comments up and running so I'll post the PHP code for how I got it working soon. I'll also be adding it to version 3.0 of my Picasa API, so look for that in the next month or two.

Comments

Abi said...

Hey Cameron,
Your API is absolutely great. After numerous searches and googling, your API turned out to be the best for my use. Thank you very much for this.
Lately, I have been playing around with comments. I was able to post comments from my website directly on to Picasa using the same trick that you used. However, I am unable to retrieve the comments using the getComments() method. When i try to check the number of comments posted using the getCommentCount() method, I get the right result.
I'm trying to do something like $image->getComments where $image is one image from $image_array. $image_array is the result of the getImages() call with the Picasa instance. Any clue what I'm doing wrong? Thanks.

Posted Friday, January 14, 2011 at 7:28 AM.
RGuttroff said...

Hallo Cameron,

I have some problems to write the code for posting new comments to a pic. Have you some example for me? I am working with typo3 and I would like to write an extension for it. I hope you can help me.

Great work. I love it

Posted Tuesday, April 28, 2009 at 2:18 AM.
James Mortensen said...

Hi Cameron,

Having comments about your photos stored as comments submitted using your Picassa account is a cool workaround to requiring users to login, and your hack may really be the only solution for bloggers who don't have access to a datasource.

I was just thinking, however, that if you do have access to a datasource, such as a database or XML file, you could store comments about your photos on your server!

For instance, if you have a picture called "ducks08.jpg" and someone leaves a comment, you could store the comment in a table with 3 columns, one for the filename/url, one for the comment, and one for the name of the user who left the comment.

An XML mapping could solve the problem as well, but I always get tied in knots with XML :)

However, since I use Blogger, your solution may be the only way someone like me, without access to a server, could enable comments on photos. Excellent article!

Posted Wednesday, February 27, 2008 at 7:53 PM.
Monday, February 18, 2008

Lightweight PHP Picasa API Version 2.0

I haven't had a chance to post in a while, I've been busy preparing an update to the Picasa API I built for the Pictures section of this site. I didn't put a whole lot of effort into making the previous implementation much better than what I needed because I didn't think it would be worthwhile. However, it's been by far the most popular part of my site and I've received some good feedback on it. So now it's time to unveil version 2.0 of the Lightweight PHP Picasa API:

Download the API here.

In the new version I've focused heavily on documentation, because one of the gripes I heard from people was that it was tough to get something started. So I've added Javadoc style commenting to all the files included and will host the Javadocs here in a few days. Also to help things out, I've added several helper functions for doing things like retrieving an album or a photo, etc. So I think it will be much easier to get started if you're downloading it for the first time.

The two new classes I've added to the API itself are the Picasa_Author and Picasa_Comment classes. You probably haven't noticed, but I've started displaying comments on each photo (see this one, for example). I haven't got comment posting to work through the API yet, but at least now I can retrieve them. So the Picasa_Comments class holds comments and the Picasa_Author class holds authors. An author could be the author of an album or a comment, depending on the situation.

If you're already using version 1.0 of the software, don't worry, I've made this one fully backwards compatible. You should be able to replace version 1.0 with version 2.0 and your interacting code should need no update.

As always, if you have any questions or comments, let me know!

Update 04/09/2008: This post is for Version 2.0 of my Lightweight PHP Picasa API. Version 3.0 has since been released, which includes a great deal of expanded functionality. Go get it here for more Picasa PHP fun!

Comments

Anonymous said...

Wooowww! Coool!

Posted Saturday, September 4, 2010 at 4:10 AM.
Anonymous said...

can you make a webpage that anyone can upload pictures to my picasa,and I can delete some bad pictures?

then another webpage disply thoese pictures i choose.

Is that possible ?

shenyang2007##Gmail.com

Posted Sunday, September 21, 2008 at 1:08 AM.
Cameron said...

Well I'm glad someone will be hotly anticipating the next release :)

Just to update everyone, the next version is coming along really well. I've just gotten accessing private albums to work (which was a lot tougher than you might expect...), and it's turning out to be a huge improvement over the current version. I'm working on it whenever I have free time and hope to have it ready in the next two weeks.

Posted Saturday, March 22, 2008 at 11:51 PM.
Anonymous said...

Hi,
Thanks for your reply! Sounds great! I will be lazy then and wait for your release ;-) Keep on the good work!
Greetings from Europe

Posted Wednesday, March 12, 2008 at 1:21 AM.
Cameron said...

Well, supporting private albums is sort of a tricky question. There is currently no method in the API that will facilitate Google's authorization process, so out of the box there is no way to do it. However, you can write something to request authorization from Picasa and then request a list of private albums. At that point, yes you could store those albums in the API's classes.

I've never needed to do authorization for my purposes until I added commenting to my photos a few weeks ago. Since I've done the work to do that, Version 3.0 of my API will include methods for authorizing an account, posting comments and photos, and I can include fetching non-public albums as well. I'm not entirely sure about a release date but I would think it will take me about a month to finish.

If anyone wants to be alerted when version 3.0 gets released, I don't have a mailing list set up but just send me your email address I'll be sure to send out a mass email once it goes online. I think it will offer a lot of improvements and make the API easier to use, and it will be fully backwards compatible with versions 1 and 2.

Posted Tuesday, March 11, 2008 at 12:22 PM.
Anonymous said...

Hi,
Seems to be a great API so far. One question: Does this work with non-public albums (as declared in Picasa web)?
Thanks

Posted Tuesday, March 11, 2008 at 2:32 AM.
Wednesday, December 12, 2007

Yesterday's News

Is was brought to my attention about a week ago that the new version of Zend, released on November 30th, now supports Picasa. This was the support that I was looking for but could not find back in July when I wanted to add pictures to my site and was also the reason that I created my PHP interface for Picasa. So while this is good news for the community, it sort of leaves my work in the dust. I think once the holidays over I'll start moving my current implementation to the new Zend framework, the Pictures section included. I've already had some feedback that it might be a better idea to try to use my work with Zend so who knows, my code may have some life left. If anyone has any feedback on the new Zend framework that they want to share, please email me or leave a comment.

Comments

Cameron said...

Just as a quick update, my Picasa API continues to be the most popular part of the site, so as long as people find it useful, I'll continue developing it. If you haven't already tried version 2.0, check it out.

Posted Thursday, February 21, 2008 at 11:07 PM.
Sunday, December 2, 2007

Help With the Picasa API in PHP

I gave some examples for my Picasa API in PHP in an earlier post (here) but I thought it deserved an entire post. The thing that can get confusing is that the API builds its objects using the queries described in Google's documentation. For instance, the code I posted earlier:


public function getAlbumsForDefaultAccount() {
     return new Picasa_Account(Cam_Util_PictureUtil::
         $BASE_QUERY_URL.'?kind=album');
}

However, this can also be a little tricky. So here's a quick method that will let get you all the public albums for any account. All you need to know is the User ID of the album's owner:

public function getAlbumsByUser($userid) {
     return new Picasa_Account('http://picasaweb.google.com/data/feed/
         api/user/'.$userid.'?kind=album');
}

Keep in mind that I haven't tested that code, so there could be a typo that I overlooked, but that's the idea. And as I said in the previous post, I would take most of that query string and put it into a constant so that if Google ever changes the format for the URL, it's easy to update all of your queries at once.

In case the idea still isn't clear, how about some code to get all the pictures from an album? All you need is the User ID and the album name:

public function getPicturesByAlbumAndUser($userid,$album) {
     return new Picasa_Album('http://picasaweb.google.com/data/feed/
         api/user/'.$userid.'/album/'.$album.'?kind=photo');
}

Now you should have an Album object with Picture objects for all the pictures in the album. It will also contain information about the albums such as location, date, etc. The information is all stored in the private members of the Album class and they are accessible through public getter and setter methods.

I hope this helps everyone. If it's still not clear, feel free to let me know. Again, feel free to download my API by clicking here.

Update 04/09/2008: This post is for Version 1.0 of my Lightweight PHP Picasa API. Version 3.0 has since been released, which includes a great deal of expanded functionality. Go get it here for more Picasa PHP fun!

Comments

Cameron said...

Matic,

In the version of the API that this article refers to, it was not possible to upload photos. It now is, however. You can read how to do it here:

PHP Picasa API Version 3.0

Posted Wednesday, March 10, 2010 at 8:28 AM.
Matic said...

Dear Cameron,

How to upload pics to picasa album via webpage?

Any sample code?

Matic

Posted Wednesday, March 10, 2010 at 12:13 AM.
Cameron said...

Starting in version 3.0 of the API, you can upload photos to your Picasa account using PHP. So you could build an interface for someone to upload photos to their own account using this API, for instance.

Posted Monday, May 26, 2008 at 12:40 PM.
Matthew Kooshad said...

Does this allow for upload to Picasa via the webpage? That's what I'm trying to figure out,
thanks!

Posted Sunday, May 25, 2008 at 11:38 PM.
Xinzhou said...

Thank you for your PHP API
I can access my albums and show icon from albums. but when I use $album->getImages() that should be return images object array from an album, but it didn't return anything. I used count($images), it return 0 for all my albums. Please see what's happen or I did something wrong to use your API.
Thanks
Nick

Posted Monday, February 25, 2008 at 6:39 PM.
Cameron said...

Hmm, strange. Well, I'm away from home on vacation for the next few days but I'll try to get some more examples up after the holidays. If you keep playing with it and figure it out before then, go ahead and post what kind of difficulty you were having and how to solve it. Thanks!

Posted Tuesday, December 18, 2007 at 8:45 AM.
Anonymous said...

I don't know, how to show pictures on webpage... I can access Account atributes, but I can't access Album... Can you post code to show pictures on page, please.

Posted Tuesday, December 18, 2007 at 3:49 AM.
de:code said...

Nasty little script. Thank you!

Posted Tuesday, December 4, 2007 at 2:35 AM.
Monday, November 12, 2007

Lightweight PHP Picasa API

As I've mentioned before, the Pictures section of this site is run through Picasa, Google's picture service. So I upload all my pictures to Picasa through a local application that they provide, I group them into albums, name them, give them a location, etc, and then they appear on CameronHinkle.com. This works out really well because their interface is nice for uploading photos and I don't have to pay for storage (I'm only using 13% of my total space and I can buy more if I need it). I also like that it's hosted in a central place with a lot of other photos because that means it's not sectioned off in its own little corner of the world. I don't usually get hung up on privacy concerns so the fact that I don't have control over the physical location of the photos does not bother me in the least.

Anyway, all of this magic is brought to you by Picasa's API. When I started this project, I was under the impression that Picasa, like Blogger, had a really slick API written in PHP that I could easily integrate with my site. It was going to be a piece of cake. Well, that turned out to not be the case. There was no existing PHP API, only one in XML, which meant I had to start the task of parsing lots of XML (which fortunately is really easy in PHP). To make things easier, I made my own PHP API that can really be used by anyone. So if you have a Picasa account and you know PHP, this makes it relatively simple to display your Picasa pictures on your website. And now for the first time, I'm publishing it on the web.

Click here to download my lightweight Picasa API in PHP.

The API is not great, it does exactly what I need it to do and not a whole lot more. However, it's extraordinarily easy to add on to. Basically it is set up with 4 types of objects that are simple to understand: Accounts, Albums, Images, and ImageCollections. Accounts have Albums, Albums have Images, and ImageCollections also have Images. Everything is pretty self explanatory except possibly ImageCollection, which is just a way to contain several images that are not from the same Album because there are different rules (like ImageCollections aren't given a title). The easiest way to understand how each class works is to look at it's constructor because that will tell you what to pass in to make a given object. Be aware that if you only need one photo, creating an entire Account object will take forever, so there's an easy way to create just a single Image object.

If you want to publish your uploaded photos on the web, this is perfect! If you want to upload your own photos, it's not so good, but it may be a good start. Hopefully someone needs to do more than I did and runs with the idea. However, I assume that there will be a Zend package available for Picasa within the next 6 or 12 months, at which point my API will be completely obsolete. Until then, enjoy!

Update 04/09/2008: This post is for Version 1.0 of my Lightweight PHP Picasa API. Version 3.0 has since been released, which includes a great deal of expanded functionality. Go get it here for more Picasa PHP fun!

UPDATE 12/2/2007: I eventually took the time to post some help with using this download and that article is posted here. I will probably offer additional help later.

Comments

Anonymous said...

Hi Cameron,
I have written a small script (using yours files) to create a list of all my picasa albums with their icon but I'm not able to give a link to each album. The name of the album is different from the href that I must give to the icon.
Have you got any suggestion?
thanks!

Andrea

Posted Saturday, November 8, 2008 at 7:42 AM.
Carbonracer said...

Hey Cameron,

just wanna say thanks for such a great work. I just got it running in a test environment. And it works just perfect. I already tried with the Zend API. But it was just to complex for my target. So I am glad you made that job. Easy to use and self explaining source code. Great!!! And besides you created a great info pool with this blog. Loved reading it. Hope, you'll have time (and be motivated) to continue working on it. Eventhough I couldn't point to things having to be improved.

Greez, Andi

Posted Thursday, July 3, 2008 at 2:59 AM.
Anonymous said...

I am not so much good in this things but i like to learn with other examples ..i checked this 4 files but i dont know how to include api & album id to this??sorry for my simple doubt ..thanks you

Posted Monday, December 31, 2007 at 7:30 AM.
curiousMe said...

hi Cameron,

i have downloaded your 4 files for picasaweb API in PHP. i somehow couldn't get it to work. I have written a simple script to instantiate the class but i get a lot of errors.

here is what my script that calls the classes :

require_once 'Account.php';
$myPicasa = new Picasa_Account("http://picasaweb.google.com/xxxxxxxx");

the error i got when i tried is quite a lot:


Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 7: parser error : EntityRef: expecting ';' in /Picasa/Account.php on line 64

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: aweb.google.com/data/feed/base/user/xxxxxxxxxx kind=album&alt in /home/hensono/public_html/assets/Picasa/Account.php on line 64

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /Picasa/Account.php on line 64

would really appreciate your help.

Posted Wednesday, December 19, 2007 at 4:51 PM.
Cameron said...

Sure, I can give an example. I should probably take some time and dedicate a whole post on how to do it, but for now I'll just do it here.

The API uses the query structure outlined in Google's documentation. Each data type in my API takes a query (or raw XML) as an argument for the constructor. You form a picasaweb.google.com query URL, send it to the constructor of the data type you're going to use, and it will return the data associated with the query you sent. For instance, here is the code I use to get an array of public albums in my Picasa account:

public function getAlbumsForDefaultAccount() {
return new Picasa_Account(Cam_Util_PictureUtil::$BASE_QUERY_URL.'?kind=album');
}

You can see I've stored the base part of the query (which doesn't ever change throughout my site) into a static field. Then to put the albums into an array:

$account = $picServ->getAlbumsForDefaultAccount();

$account is then an array that I can use in a foreach just like any other array. I use the getter methods for each element in the array to access the individual fields in the Album class.

One thing to keep in mind is that when you create an Account object, it creates each Album object but does not create Picture objects within each Album. This is true in the atom feed and I had initially changed it so that it created each picture object for the entire account, but the performance was terrible.

Hope this helps!

Posted Tuesday, November 27, 2007 at 1:06 PM.
Anonymous said...

hello, can show us example on how to use your php files? thank you.

Posted Tuesday, November 27, 2007 at 7:23 AM.
Sunday, September 9, 2007

Arcadia Beach Roadie 2007

Over Labor Day Weekend, me and the old high school gang got together for a camping trip. While it was without a doubt the worst planned camping trip ever (especially for Labor Day Weekend), it actually turned out pretty well. We had no idea where we were going to stay but we headed out Friday night at about 8:00 for the coast. Without a place to lay our head, we drove up and down the 101 for 45 minutes in the dark of night, stopping wherever we thought we saw a possible campsite. Finally, around 11:00, we found our final destination.

"Camping Prohibited!" said the sign at the front of the beach, but we didn't care. We didn't really have much choice, really. We saw some cars in the parking lot and investigated a little further; indeed, at least 3 other groups had pitched tents on the beach. So we found a place that wasn't too intrusive and started hauling our stuff down the steps to the sand.

Saturday was a gorgeous day. Bright and sunny, but with a little breeze as well. It was one of the nicest days I've spent at the beach. I didn't leave the beach the entire time, except to go back to the car. I did a lot of reading, took a lot of pictures, and watched Heim almost kill himself. Oh yeah, Heim almost killed himself. He climbed up some pretty steep rocks and after he'd gotten about 30 feet off the ground, realized his footing was largely unstable. We realized it too, when we saw large rocks falling from the cliff and making a loud THUD! as they hit the wet sand below. Anyway, he eventually found a way back down, but it was a little tense for a while. He even drew quite a crowd, as you can see in the picture.

The next morning, we awoke to a loud voice, "You are in violation of Oregon State law. It is a $97 fine for camping on the beach. I'm giving you 30 minutes to pack up and leave, at which point I will start handing out citations. You are all banned from the beach for 48 hours." The ranger was pretty cool; he took all of our id information and then pretty much left us along while we packed up. It worked out for the best, really; I wanted to leave early and this gave everyone a reason to pack up as quickly as possible. We're all just glad he somehow missed us on Saturday morning.

In related news, if you'd like to see pictures of our trip, you can now do so here. Some of you may have noticed that the Pictures section is sort of working now. It's not pretty, but you can see all the pictures in my Picasa account, which is a pretty big accomplishment. There aren't any PHP tools available for the Picasa integration like there was for the Blogger integration, so it's ended up being an entirely different experience trying to make the pictures show up. While the style is nowhere near where it needs to be, the pictures are all there. I did a little home-brew API in PHP to handle all the XML parsing from Google's Atom feed. I'll go through what I did to set that up at a later time and post my code for download in case anyone wants it. I'm not taking the time to make it really robust, but if someone wants to add data that I leave out, they can easily add to it. Look for that in the next few weeks and look for the pictures section to be finished later this week.

The articles in this blog are authored by Cameron Hinkle, Software Engineer for Nike. The thoughts and opinions expressed are not shared by Nike or any of its affiliates.