Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a user's Instagram feed

Tags:

php

instagram

I'd like to get a user's Instagram feed using PHP. I've signed up for an Instagram Developer Account and tried pulling in a user's info and photos, but the response isn't stable. Sometimes I get a response and other times I keep getting the error: access_token is missing. Is there a solid example of getting a user's feed of photos by username?

Ideally, I'd like it to be as simple as:

$instagram = new Instagram();
$photos = $instagram->getPhotos("username-goes-here");

Where Instagram is a class that handles all the requests. Any help or direction is appreciated. Thanks!

like image 837
jaysonp Avatar asked Jun 10 '11 19:06

jaysonp


People also ask

Why can't I see someone's posts on Instagram but not blocked?

If the account is private and you're unable to find it upon searching. Then, you can't really say that they have blocked you. However, if the account is public, and while searching for their page, you can't see any posts, their profile picture, followers count or the following count.

What is user Feed in Instagram?

Instagram Feed is a place where you can share and connect with the people and things you care about. When you open Instagram or refresh your feed, the photos and videos we think you care about most will appear towards the top of your feed.


2 Answers

Try this,

<?php

  function fetchData($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;
  }

  $result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE");
  $result = json_decode($result);
  foreach ($result->data as $post) {
    // Do something with this data.
  }
?>

May this help you.

like image 74
Tony Stark Avatar answered Sep 22 '22 18:09

Tony Stark


I did this:

<?php

  function fetchData($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;
  }

  $result = fetchData("https://api.instagram.com/v1/users/USER ID HERE/media/recent/?access_token=ACCES TOKEN HERE&count=14");


  $result = json_decode($result);
  foreach ($result->data as $post) {
     if(empty($post->caption->text)) {
       // Do Nothing
     }
     else {
        echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
        <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" />
        <div class="instagram-desc">'.htmlentities($post->caption->text).' | '.htmlentities(date("F j, Y, g:i a", $post->caption->created_time)).'</div></a>';
     }

  }
?>
like image 41
LookingLA Avatar answered Sep 21 '22 18:09

LookingLA