The AS3 Flickr API on Google Code (as3flickrlib) is a great tool for integrating Flickr into your Flex or Flash application.
But if you want to include the SWC in a Flex 3 or AIR project, you need to download the source code and recompile it as a Flex 3 Library. The SWC included in the zip file is compiled for Flex 2 and will generate a runtime error when you try to instantiate an instance of FlickrService.
Once you have the Flex 3 SWC in your project, using the actual Flickr API is pretty straightforward. As with all third-party Flickr apps, you first need to authenticate your application for a Flickr user.
Here’s a simplified version of the login process:
|
var flickr : FlickrService = new FlickrService (YOUR_FLICKR_API_KEY); flickr.secret = YOUR_FLICKR_API_SECRET; flickr.addEventListener (FlickrResultEvent.AUTH_GET_FROB, onGetFrob); // starts the Flickr login process flickr.auth.getFrob (); private function onGetFrob (event : FlickrResultEvent) : void { if (event.success) { var frob : String = event.data.frob as String; var authURL : String = flickr.getLoginURL (frob, AuthPerm.READ); navigateToURL (new URLRequest (authURL), “_blank”); } } |
The authURL is the page on Flickr where you authenticate your application. Your app needs to be authenticated before you can retrieve an auth token:
|
flickr.addEventListener (FlickrResultEvent.AUTH_GET_TOKEN, onGetToken); flickr.auth.getToken (frob); private function onGetToken (event : FlickrResultEvent) : void { if (event.success) { var authResult : AuthResult = event.data as AuthResult; flickr.token = authResult.token; flickr.permission = authResult.perms; } } |
Once you have an auth token, you should have access to the private information in the user’s account, and depending on the permission level, the ability to add, edit and delete photos and metadata.

3 comments
Comments feed for this article
February 19, 2009 at 11:55 am
Tweaking The AS3 Flickr API in Flex and AIR « Miscellanea
[...] from recompiling the SWC (see here), here are the bugs I’ve found and some of the changes I’ve [...]
November 30, 2009 at 3:33 am
mmunera
Hi.
Do you know how to implement this service (flickr.photosets.comments.addComment) from the Flickr API?
Greetings.
November 30, 2009 at 8:18 pm
Nick Schneble
@mmunera
The easiest way is to simply use a REST call, which would be something like:
http://api.flickr.com/services/rest/?method=flickr.photosets.comments.addComment&name=value
For the list of arguments to pass into the call, and the expected response format, I’d check out the page for the addComment call here:
http://www.flickr.com/services/api/flickr.photos.comments.addComment.html