Ethelcofie’s How To Articles

May 19, 2008

Flickr API: How to perform Authentication using PHP

Filed under: Development Articles — ethelcofie @ 1:32 pm
Tags: ,

I presented this at Brighton BArCamp3 download power point

//1.Create a login link

$secret_key=’secret key’;

$params = array(
‘api_key’=> ‘api_key’,
‘perms’ => ‘write’);

$encoded_param = array();

//1.a Encode and organize authentication parameters

foreach($params as $key => $value)
$encoded_params[] = urlencode($key).’=’.urlencode($value);

//1b Create the api signature :an md5 of the parameters in alphabetic order


//1.c append api signature to url

$url =””.


header(‘Location:’.$url); –>This will then redirect back to your call back url and include a frob value

//2.Get and use frob to retrive authentication token

//2.a Get frob from url

if ($_REQUEST[‘frob’])
//using php_serial paramater serial to retrieve the format in serialized data structure
$frobparams = array(
‘api_key’=> ‘api_key’,
‘frob’ => ‘frob’ ,
‘method’ => ‘flickr.auth.getToken’,
‘format’ => ‘php_serial’);

$encoded_param = array();

foreach($frobparams as $key => $value)
$encoded_params[] = urlencode($key).’=’.urlencode($value);
$url = “”.implode(‘&’, $encoded_params);

//2.bCreate the api signature :an md5 of the parameters in alphabetic order



‘api_key’. $frobparams [‘api_key’].

‘format’.$frobparams [‘format’].



//2.c Construct url to auth.getToken


// 2.d Get url response/contents
$rsp = file_get_contents($url);

$rsp_obj = unserialize($rsp);


//2.e Glean Auth Token from $details

echo $details[‘auth’][‘token’][‘_content’];

//dispaly error message if there is a problem
echo $details [message] ;



Just getting started: The Authentication Token can then be ussed as part of the parameter for a method call


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: