Main

January 14, 2008

Creating authenticated/signed Flickr API calls in Flex/Actionscript

Since the individual doc pages for the Flickr API calls don't tell you how to create a signed API call, it took me a minute to figure it out. This info can be found in the Flickr User Authentication docs, but here's how to create a signed call.

Let's say you want to call flickr.people.getUploadStatus.
Well, the call requires authentication or else it won't do you any good. Once you are authenticated you create the call by performing the following steps:

1) Create a string using the required parameter names plus their values in alphabetical order (i.e. "api_key" + api_key_value .) Then preceed this string with the shared_secret, and append the string with the string "method" plus the method name. Note that every authenticated call requires both the auth_token and api_sig arguments.

So, in the case of flickr.people.getUploadStatus the string would look something like:

var api_sig : String = shared_secret + "api_key" + api_key_value+ "auth_token" + token_value + "method" + "flickr.people.getUploadStatus"

2) Then get the MD5() of this string. As I mention in another post, I use this class, and simply call MD5.encrypt( myString )

var api_sig_encrypted : String = MD5.encrypt( api_sig );

3) We can then make the call:

var params : Object = { "method": "flickr.people.getUploadStatus", "api_key": api_key, "api_sig" : api_sig_encrypted, "auth_token" : auth_token }; 
codeService.request = params;
codeService.url 	= "http://api.flickr.com/services/rest/";

codeService.addEventListener( ResultEvent.RESULT, getUploadStatusResult );
codeService.addEventListener( FaultEvent.FAULT, faultResult );

codeService.send();

MD5 for Actionscript

I'm working on a Flex/AIR application that requires Flickr authentication so I needed an MD5 class for Actionscript. Here's the one i've been using and it's been working great. It's simple and doesn't have a load of extra unnecessary baggage.