Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instagram display user follower example.Simply replace the success.php file in the example folder by this one and fill in your API credentials.
{
"username": "moo",
"bio": "We print things.",
"website": "http://www.moo.com",
"profile_picture": "http://images.ak.instagram.com/profiles/profile_7927894_75sq_1378988556.jpg",
"full_name": "MOO Print",
"id": 7927894
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Instagram follower example</title>
<meta name="author" content="Christian Metz">
<!--
Instagram PHP API class @ Github
https://github.com/cosenary/Instagram-PHP-API
-->
<style>
* {
margin: 0;
padding: 0;
}
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
ul > li {
list-style: none;
padding: 4px;
}
.avatar {
background-size: 40px auto;
border-radius: 50%;
display: inline-block;
height: 40px;
margin-right: 8px;
vertical-align: middle;
width: 40px;
}
</style>
</head>
<body>
<?php
/**
* Instagram PHP API
* show list of users a user is followed by
*
* @link https://github.com/cosenary/Instagram-PHP-API
* @author Christian Metz
* @since 01.10.2013
*/
require 'Instagram.php';
use MetzWeb\Instagram\Instagram;
// Initialize class
$instagram = new Instagram(array(
'apiKey' => 'YOUR_APP_KEY',
'apiSecret' => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK'
));
// Receive OAuth code parameter
$code = $_GET['code'];
if (true === isset($code)) {
$data = $instagram->getOAuthToken($code);
echo 'Your username is: ' . $data->user->username;
$instagram->setAccessToken($data);
$follower = $instagram->getUserFollower();
echo "<ul>";
do {
// loop through all entries of a response
foreach ($follower->data as $data) {
echo "<li><div class=\"avatar\" style=\"background-image: url({$data->profile_picture})\"></div> $data->username ($data->full_name)</li>";
}
// continue with the next result
} while ($follower = $instagram->pagination($follower));
echo "</ul>";
}
?>
</body>
</html>
@C-onnor

This comment has been minimized.

Copy link

commented Jan 16, 2014

When I run this, $follower keeps displaying the same first 50 followers in an endless loop.

@nabeel-alalmai

This comment has been minimized.

Copy link

commented Jan 19, 2014

Hi, I got the same as C-onnor ,, infinity loop displaying the first 50,, how to solve that??

@cosenary

This comment has been minimized.

Copy link
Owner Author

commented Feb 2, 2014

This issue is caused by Instagram's inconsistent pagination return type. It's fixed in version 2.1. As @C-onnor pointed out, there is actually a follow count bug.

@ghost

This comment has been minimized.

Copy link

commented Apr 28, 2016

I would like to tell you that I was trying your above code to get list of followers and am testing the same on http://reviewitapp.co/prak/instagramPHP/example but instead of getting any list of followers I get "Your username is: thuglifesingh" and the rest of the page is blank? What's the reason? Is it because the code has some issue?

@shubha6444

This comment has been minimized.

Copy link

commented Sep 9, 2016

i am using this code but get error sig paramter like this stdClass Object ( [code] => 403 [error_type] => OAuthForbiddenException [error_message] => Invalid signed-request: Missing required parameter 'sig' )

@PabloVallejo

This comment has been minimized.

Copy link

commented Nov 2, 2016

Thanks for the snippet!

Is there a way to get the list of followers of a specific user id?

👍

@monajalal

This comment has been minimized.

@sirdash

This comment has been minimized.

Copy link

commented Feb 13, 2019

Fatal error: Uncaught Error: Class 'MetzWeb\Instagram\InstagramException' not found in /home/MYSITE/public_html/insta/src/Instagram.php:538 Stack trace: #0 /home/MYSITE/public_html/insta/success.php(70): MetzWeb\Instagram\Instagram->pagination(Object(stdClass)) #1 {main} thrown in /home/MYSITE/public_html/insta/src/Instagram.php on line 538

i have a error :-)
please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.