How to get Facebook subscriber count + friend count

1.4k views Asked by At

Until few weeks ago I was able to get subscriber count & friend count for personal accounts in Facebook. Here's the code I used:

$userid = '543766397';
$url = file_get_contents('http://api.facebook.com/method/fql.query?format=json&query=select+subscriber_count,+friend_count+from+user+where+uid%3D'.$userid);
$decode = json_decode($url);  

$fb['subscriber_count'] = $decode[0]->subscriber_count;
$fb['friend_count'] = $decode[0]->friend_count;

Facebook has made changes to their service and the code above isn't working any more. I've tried to find solution this problem for several days but it seems that either I don't know how to find the answer or I'm alone with my problem. I know that FQL queries are legacy way of doing things and most likely feature is deprecated but I haven't found any working solution.

Any assistance would be highly appreciated!

1

There are 1 answers

1
Tobi On BEST ANSWER

First of all, the subscriber edge is deprecated since Graph API v2.0. You're calling the also deprecated REST API. You can also no longer get the friend count without having a User Access Token containing the user_friends permission.

Once you have that, you can call /me/friends to receive the total_count:

{
  "data": [], 
  "paging": {
    "next": "https://graph.facebook.com/v2.3/me/friends?limit=25&offset=25&__after_id=enc_AdAZ"
  }, 
  "summary": {
    "total_count": 123
  }
}

See

  • /me/subscribers and /me/subscribedto have been removed.

  • Friend list is no longer part of the default permission set and has its own permission: Asking for access to a person's friend list is now a separate permission that your app must request. The new permission is called user_friends.