Skip to content

Instantly share code, notes, and snippets.

@planetguru
Last active August 29, 2015 13:59
Show Gist options
  • Save planetguru/10718310 to your computer and use it in GitHub Desktop.
Save planetguru/10718310 to your computer and use it in GitHub Desktop.
<?php
// download all flickr images from a given userid
$key = "asdf";
// userid is embedded in this url
$url = "https://api.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=".$key."&user_id=120759744%40N07&per_page=100&page=";
$append = "&format=json&nojsoncallback=1";
for($i=0; $i<10; $i++){
$uri = $url.$i.$append;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$uri);
$result=curl_exec($ch);
$stuff = json_decode($result,true);
// get no. photos in total
$count=$stuff['photos']['total'];
foreach($stuff['photos']['photo'] as &$photo){
// image url is http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg
$farmid= $photo['farm'];
$serverid= $photo['server'];
$id= $photo['id'];
$secret= $photo['secret'];
$imageurl = "http://farm".$farmid.".staticflickr.com/".$serverid."/".$id."_".$secret."_b.jpg";
printf("\n%s",$imageurl);
$output = '/tmp/flickrcam/'.$id.'.jpg';
file_put_contents($output, file_get_contents($imageurl));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment