Reputation: 53
I'm trying to get the follows list from Instagram API. My profile is Admin in Sandbox Mode. But the data from the API is empty:
{"pagination": {}, "data": [], "meta": {"code": 200}}
Thats my Code:
<?php
$authcode = $_REQUEST["code"];
$clientid = "****";
$clientsecret = "****";
if (!$authcode) {
$url = 'https://api.instagram.com/oauth/authorize/?client_id='.$clientid.'&redirect_uri='.urldecode("http://localhost/ig-following").'&response_type=code&scope=follower_list';
echo '<a href="'.$url.'">Login</a>';
exit();
}
echo "Get Token..<br><br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.instagram.com/oauth/access_token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'client_id='.$clientid.'&client_secret='.$clientsecret.'&grant_type=authorization_code&redirect_uri='.urldecode("http://localhost/ig-following").'&code='.$authcode);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
$data = json_decode($server_output);
$username = $data->user->username;
$access_token = $data->access_token;
echo 'Token for '.$username.': '.$access_token.'<br><br>';
$url = 'https://api.instagram.com/v1/users/self/follows?access_token='.$access_token;
echo 'Request URL: '.$url.'<br><br>';
$data = file_get_contents($url);
echo $data;
?>
Upvotes: 0
Views: 825
Reputation: 18473
I had the same error, here's why you have this particular result:
In sandbox mode, everything happens as if the only Instagram accounts that exists are the ones shown in the "Sandbox" tab of https://www.instagram.com/developer/clients/[client_ID]/edit/. I bet five bucks that the only users that you'll find there is... you.
Therefore, when Instagram tells your app that you are followed by no one, it's because for the current state of the API, you are the only Instagram user in the world.
Let's name your main account IAmMain. To get the follow list of IAmMain, follow these simple steps:
now, if you reload https://api.instagram.com/v1/users/self/follows?access_token=[access_token] you should get something like:
{"pagination": {}, "data": [{"id": "[10 digits]", "username": "IAmOther", "full_name": "[full name]", "profile_picture": "[url]"}], "meta": {"code": 200}}
which is basically what you're looking for.
Hope that'll work as fine as it worked for me!
Upvotes: 0
Reputation: 14571
From what I know, you will only get the followers/following info for your sandbox users. So you could invite a sandbox user, start following him and then it should be displayed.
Upvotes: 1