可能您的 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。