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
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.
Does this allow for upload to Picasa via the webpage? That's what I'm trying to figure out,
thanks!
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
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!
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.
Nasty little script. Thank you!