Flickr Photos Pull-In PHP JSON


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $flickrId = 'userId'; // Find your Flickr ID at http://idgettr.com
  3. $flickrrequest = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $flickrId . '&format=json';
  4. $flickrci = curl_init($flickrrequest);
  5. curl_setopt($flickrci,CURLOPT_RETURNTRANSFER, TRUE);
  6. $flickrinput = curl_exec($flickrci);
  7. curl_close($flickrci);
  8.  
  9. // Flickr JSON doesn't come in standard form, some str replace needed
  10.  
  11. $flickrinput = str_replace('jsonFlickrFeed(','',$flickrinput);
  12. $flickrinput = str_replace('})','}',$flickrinput);
  13.  
  14. // parameter 'true' is necessary for output as PHP array
  15.  
  16. $flickrvalue = json_decode($flickrinput,true);
  17. $flickritem = $flickrvalue['items'];
  18.  
  19. // echo the channel information
  20.  
  21. echo "<h3><a href=\"" . $flickrvalue['link'] . "\">" . $flickrvalue['title'] . "</a></h3>\n";
  22. echo "<p>" . $flickrvalue['description'] . "</p>\n";
  23.  
  24. $photosToDisplay = 5; //change this to the number of photos you want to display
  25.  
  26. for($p=0;$p<$photosToDisplay;$p++){
  27. echo "<a href=\"" . $flickritem[$p]['link'] . "\"><img src=\"" . $flickritem[$p]['media']['m'] . "\" /></a>\n";
  28. }
  29.  
  30. echo "<p><a href=\"" . $flickrvalue['link'] . "\">View all my photos</p>\n";
  31. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.