Use PHP to pull Users Instagram Feed

Published: 16, Sep 2015
DevelopmentPHP
<?php
   function fetch_data($url){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 20);
      $result = curl_exec($ch);
      curl_close($ch);
      return $result;
   }
   
   $count = 10; // the number of photos you want to fetch
   $access_token = "###################"; // Put your access_token which is generated from instagram here
   $display_size = "thumbnail"; // you can choose between "low_resolution", "thumbnail" and "standard_resolution"

   $result = fetch_data("https://api.instagram.com/v1/users/17368863/media/recent/?client_id=$access_token");
   $result = json_decode($result);
   
   ?>
<ul class="slides" >
   <?php
      foreach ($result->data as $photo):
         $img = $photo->images->thumbnail->url;
         $imageLink  =  $photo->link;
      
      ?>
   <li style="width: 185px; float: left; display: block;">
      <a href="<?php echo $imageLink; ?>" target="_blank">
      <img src="<?php echo $img; ?>" draggable="false">
      </a>
   </li>
   <?php
      endforeach;
      ?>
</ul>

 

Here’s a great snippet for pulling a users Instagram Feed and doing whatever you want with it. 🙂