Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 19th, 2012  |  syntax: PHP  |  size: 1.27 KB  |  views: 90  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.                         function get_instagram($user_id=15203338,$count=6,$width=190,$height=190){
  3.  
  4.                             $url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf&count='.$count;
  5.  
  6.                             // Also Perhaps you should cache the results as the instagram API is slow
  7.                             $cache = './'.sha1($url).'.json';
  8.                             if(file_exists($cache) && filemtime($cache) > time() - 60*60){
  9.                                 // If a cache file exists, and it is newer than 1 hour, use it
  10.                                 $jsonData = json_decode(file_get_contents($cache));
  11.                             } else {
  12.                                 $jsonData = json_decode((file_get_contents($url)));
  13.                                 file_put_contents($cache,json_encode($jsonData));
  14.                             }
  15.  
  16.                             $result = '<div id="instagram">'.PHP_EOL;
  17.                             foreach ($jsonData->data as $key=>$value) {
  18.                                 $result .= "\t".'<a class="fancybox" data-fancybox-group="gallery" title="'.$value->caption->text.' '.$value->caption->created_time.'" style="padding:3px" href="'.$value->images->standard_resolution->url.'"><img src="'.$value->images->low_resolution->url.'" alt="'.$value->caption->text.'" width="'.$width.'" height="'.$height.'" /></a>'.PHP_EOL;
  19.                             }
  20.                             $result .= '</div>'.PHP_EOL;
  21.                             return $result;
  22.                         }
  23.  
  24.                         echo get_instagram();
  25.                         ?>