$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_”前缀。
根据Instagram API Docs,followed_by
is a child of counts
which is a child of data
.
https://api.instagram.com/v1/users/1574083/?access_token=ACCESS-TOKEN
回报:
{
"data": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
"bio": "This is my bio",
"website": "http://snoopdogg.com",
"counts": {
"media": 1320,
"follows": 420,
"followed_by": 3410
}
}
因此,以下应该有效。
<?php
$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
$api_response = file_get_contents($url);
$record = json_decode($api_response);
echo $record->data->counts->followed_by;
// if nothing is echoed try
echo '<pre>' . print_r($api_response, true) . '</pre>';
echo '<pre>' . print_r($record, true) . '</pre>';
// to see what is in the $api_response and $record object
尝试这个..
<?php
$instagram = "https://api.instagram.com/v1/users/xxxxx/?access_token=xxxxx";
$instagram_follows = json_decode(file_get_contents($instagram))->data->counts->followed_by;
echo $instagram_follows;
?>
function get_https_content($url=NULL,$method="GET"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0');
curl_setopt($ch, CURLOPT_URL,$url);
return curl_exec($ch);
}
function ig_count($username) {
return json_decode(get_https_content("https://api.instagram.com/v1/users/1460891826/?client_id=ea69458ef6a34f13949b99e84d79ccf2"))->data->counts->followed_by;
}
这是我的代码:)
试试这个...
$url = 'https://api.instagram.com/v1/users/USER_ID?access_token=YOUR_TOKEN';
$api_response = file_get_contents($url);
$record = json_decode($api_response);
echo $followed_by = $record->data->counts->followed_by;
点击获取用户的所有信息