您的client_id可能处于沙盒模式 . 您无法从白名单以外的帐户获取信息 . 如果您向应用程序发送评论,则可以退出沙盒模式 .
但是有一个更简单的解决方案 . 您只需拨打一个电话即可从网络版(无需API)获取公开信息:
$otherPage = 'nasa';
$response = file_get_contents("https://www.instagram.com/$otherPage/?__a=1");
if ($response !== false) {
$data = json_decode($response, true);
if ($data !== null) {
$follows = $data['user']['follows']['count'];
$followedBy = $data['user']['followed_by']['count'];
echo $follows . ' and ' . $followedBy;
}
}
Update. 对不起,我误解了你的问题 . 可以在没有API的情况下获取列表 . 您需要cookie中的csrf令牌和用户ID,然后调用查询:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/query/");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//You need the csrftoken, ds_user_id
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: ..."));
curl_setopt($ch, CURLOPT_POST, 1);
$userId = 528817151;
curl_setopt($ch, CURLOPT_POSTFIELDS,
"q=ig_user($userId) {
followed_by.first(10) {
count,
page_info {
end_cursor,
has_next_page
},
nodes {
id,
is_verified,
followed_by_viewer,
requested_by_viewer,
full_name,
profile_pic_url,
username
}
}
}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
您可以在Instagram网站上获取正确的cookie进行登录操作 .