Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
// download all flickr images from a given userid
// userid is embedded in this url
$key = "enterkeyhere";
$url = "https://api.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key=".$key."&user_id=120759744%40N07&per_page=80&page=";
$append = "&format=json&nojsoncallback=1";
for($i=1; $i<4; $i++){ // 3 pages of 80 images
$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);
date_default_timezone_set("Europe/London");
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'];
$title= $photo['title'];
$timestamp = strtotime($title);
printf("\n%s",$timestamp);
$imageurl = "http://farm".$farmid.".staticflickr.com/".$serverid."/".$id."_".$secret."_b.jpg";
printf("\n%s",$imageurl);
$output = '/tmp/flickrcam/'.$timestamp.'.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