【发布时间】:2017-07-13 20:52:47
【问题描述】:
我正在尝试从 Instagram API 获取关注列表。我的个人资料是沙盒模式下的管理员。但是来自 API 的数据是空的:
{"pagination": {}, "data": [], "meta": {"code": 200}}
这是我的代码:
<?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;
?>
【问题讨论】:
标签: php api instagram instagram-api