问题
Using the Facebook Graph API or some other means, is there a currently-available way to get a user's follower count? You'd think it would be a simple readable metric field at the user level, but after hours of searching, I cannot find such a field.
I know Facebook considers the concept of followers to be valid, because they have a working "edge" for it with their web interface, https://www.facebook.com/user_name/followers as well as listing the account on the user's main page (see image example below).
Certainly it seems the capability to read, or at least derive, the followers count existed previously in the form of reading the "subscribers" list for a user, but that's now obsolete. An alternative method seems to have been to use FQL to query the data. This method is now also obsolete. And there are stackoverflow questions about it, a good example is here, but they seem to relate to previous capabilities no longer available.
回答1:
According to the docs, there is no possibility to get the follower count: https://developers.facebook.com/docs/graph-api/reference/user
The subscribers endpoint was removed with v2.0 already: https://developers.facebook.com/docs/apps/changelog#v2_0
Other threads about the same topic:
- how to get followers list from facebook account by graph api?
- facebook graph api to get follower count of different account
回答2:
If you have an access_token, you can call {profile-id}/insights/page_fans_country and retrieve the number of people who like the page aggregated by country. This works for any public profile.
https://graph.facebook.com/{profile-id}/insights/page_fans_country?access_token={access-token}
You could then sum up the countries to get the total number of followers. If you need to retrieve followers for your own profile, you can call page_fans which provides the total number of people who have liked your page.
回答3:
You can use fan_count:
{
"id": "235014179868339",
"name": "Zoella",
"fan_count": 2647287
}
Facebook Graph API Explorer
回答4:
This is an updated and working code snippet which can be used to retrieve Facebook like count of a specific page. To use this code snippet you’ll need a Facebook App ID and Secret Key. This use latest 2.8 API version method.
Step 1:
Go to https://developers.facebook.com/ login with your facebook account. If you don’t have one you have to create one.
Step 2:
Created an app from facebook developer.
Step3:
You have to get App ID and App Secret from app you created.
Step 4:
PHP Code to get facebook like count of a page.
<?php
function fbLikeCount($id,$appid,$appsecret){
$json_url ='https://graph.facebook.com/'.$id.'?access_token='.$appid.'|'.$appsecret.'&fields=fan_count';
$json = file_get_contents($json_url);
$json_output = json_decode($json);
//Extract the likes count from the JSON object
if($json_output->fan_count){
return $fan_count = $json_output->fan_count;
}else{
return 0;
}
}
echo fbLikeCount('coregenie','___APPID___','___APPSECRET___');
?>
Please edit your page name , app id, app secret.
This method is working. Tested on 19/12/2017
来源:https://stackoverflow.com/questions/37572559/facebook-graph-api-read-followers-count