1. Get a pair of Flickr API keys here
2. Write the code to invoke the REST url through curl, parse the xml, and transform the result into a nice array:
$ch=curl_init();
$curl_post_data = array(
"method" => "flickr.photos.search",
"api_key" => $api_key,
"lat" => $lat,
"lon" => $lon,
"radius_units" => "km",
"has_geo" => "1",
"radius" => $radius,
"accuracy" => $accuracy,
"min_taken_date" => $min_taken_date,
"max_taken_date" => $max_taken_date,
);
curl_setopt($ch, CURLOPT_URL, 'http://api.flickr.com/services/rest/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);
$xmlstr=curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($xmlstr);
$totalresults=$xml->photos['total'];
$photoresults = array();
if ($totalresults!=0){
foreach ($xml->photos->photo as $photo) {
$photoinfotmp=array();
$photoinfotmp['id']=$photo['id'];
$photoinfotmp['owner']=$photo['owner'];
$photoinfotmp['secret']=$photo['secret'];
$photoinfotmp['server']=$photo['server'];
$photoinfotmp['farm']=$photo['farm'];
$photoinfotmp['title']=$photo['title'];
$photoinfotmp['ispublic']=$photo['ispublic'];
$photoinfotmp['isfriend']=$photo['isfriend'];
$photoinfotmp['isfamily']=$photo['isfamily'];
$photoinfotmp['url']="http://farm".$photoinfotmp['farm'];
$photoinfotmp['url']=$photoinfotmp['url'].$photoinfotmp['server'];
$photoinfotmp['url']=$photoinfotmp['url']."/".$photoinfotmp['id'];
$photoinfotmp['url']=$photoinfotmp['url']."_".$photo['secret'].".jpg";
$photoresults[]=$photoinfotmp;
}
}
NOTE: For some reason, invoking the REST url with file_get_contents or curl with GET instead of POST was returning incorrect results…
Tags: Flickr, REST