Skip to content

Instantly share code, notes, and snippets.

@planetguru
Last active August 29, 2015 13:59

Revisions

  1. planetguru revised this gist Apr 15, 2014. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions get flickr user images
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    <?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=";
    $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=0; $i<10; $i++){
    for($i=1; $i<4; $i++){ // 3 pages of 80 images
    $uri = $url.$i.$append;

    $ch = curl_init();
    @@ -15,19 +15,20 @@ for($i=0; $i<10; $i++){
    $result=curl_exec($ch);

    $stuff = json_decode($result,true);

    // get no. photos in total
    $count=$stuff['photos']['total'];
    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/'.$id.'.jpg';
    $output = '/tmp/flickrcam/'.$timestamp.'.jpg';
    file_put_contents($output, file_get_contents($imageurl));
    }
    }
  2. planetguru created this gist Apr 15, 2014.
    34 changes: 34 additions & 0 deletions get flickr user images
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <?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));
    }
    }
    ?>