10.10.08
ActionScript 3 Photobucket API Basics
So by popular demand, and just because it’s fresh on my mind, I’ve revisited the Photobucket photoflow example. This version of the app goes a step further and uses the full blown ActionScript 3 Photobucket API. This API is actually relatively new and I was actually working on a similar interface to their API when they released theirs. Anyway the API details can be found here:
http://code.google.com/p/photobucketas3lib/
and of course you will need developer keys from Photobucket in order for this to work. Also since Photobucket does not have a crossdomain.xml yet, so you’ll need a local proxy if you want to use the coverflow container. I detailed a very basic one in an earlier post.
What I will do for this example is load a user’s album in Doug McCune’s photoflow container.
The Photobucket API is pretty straightforward to use. The work flow is basically the following:
1) log in to Photobucket with your developer keys
1 2 | private var login:Login = new Login(); login.setConsumer(PhotobucketKeys.CONSUMER, PhotobucketKeys.PRIVATE); |
2) Query for a user’s album information
1 | var _pbAlbum:Album = PhotobucketService.getInstance().albumFactory(user) as Album; |
3) Request all the images from the album
1 | list.dataprovider = _pbAlbum.images; |
4) List any sub-albums
1 | subAlbums.dataProvider = _pbAlbum.sub_albums; |
And that is basically it. There is some weirdness in their API in regards to the way they treat data providers. If you pass their return objects in as the dataprovider attribute to a display object you are fine, but it you want to do any advanced processing of the return values you have to do some work arounds to the way the return data to you. you can see the details in the source code below, but to put it simply they destroy the original dataprovider before they fill it with data so attaching listeners to the data provider does not work the way you expect.
Here’s the finished project. You can view the source here. To use it, enter a Photobucket user name that has public images available (private images will not be displayed) and press enter or click load. The user’s main album will show in the photoflow and all their sub-albums will show in the combobox. Select a sub-album to show it in the photoflow.
It’s pretty basic, but should give you a good starting point to jump into the Photobucket ActionScript API. My code is released under the Creative Commons Attribution license so anyone (personal or corporate) can use or modify it, just give a shout out to me if you do. Have Fun.