$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
echo json_decode(file_get_contents($url))->{'followed_by'};
我正在使用这段代码,但我不明白问题出在哪里。我是 PHP 的新手,所以请原谅新手的错误。我正在尝试让“followed_by”自行显示。我已经设法让 Facebook 的“赞”和 Twitter 的关注者以这种方式显示。
最佳答案
如果您需要在不登录的情况下获取关注者数量(或其他字段),Instagram 可以将它们放在页面源代码中的 JSON 中:
$raw = file_get_contents('https://www.instagram.com/USERNAME'); //replace with user
preg_match('/\"edge_followed_by\"\:\s?\{\"count\"\:\s?([0-9]+)/',$raw,$m);
print intval($m[1]);
//returns "123"
希望对您有所帮助。
2016 年 5 月 24 日更新为更能容忍 JSON 中的空格。
2018 年 4 月 19 日更新为使用新的“edge_”前缀。
关于php - 使用 PHP 从 Instagram 获取基本信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14414606/