skip to Main Content

I am user PHP facebook API to get the Facebook’s user data. And I am trying to get the total friends.

I am using Graph API and it return this:

{
  "id": "12312312312312",
  "name": "myName",
  "friends": {
    "data": [
      ],
    "summary": {
         "total_count": 89
    }
 }

}

But When I use my code:

$profile_request = $fb->get('/me?fields=name, friends');
$profile = $profile_request->getGraphNode()->asArray();
print_r($profile);

//It return these to me:
Array ( [name] => Myname [friends] => Array ( ) [id] => 12346677888 )

The friend array only return a null value to me.

How can I get back the total count?

thx for helping

2

Answers


  1. Facebook v2.0 upgraded you can try like this “user_friends”.

    Upgrade Link

    Login or Signup to reply.
  2. I know it’s an old question, but this may be helpful for someone since I was just looking for this answer by myself. And I found it.

    You have to get graph node without asArray to grab total_count.

    For example:

    $getGraphNode = $profileRequest->getGraphNode();
    $profile = $getGraphNode->asArray();
    

    $profile will act the same, but you will now have graph node without asArray, so you can grab total_count.

    $total_count = $getGraphNode['friends']->getMetaData()['summary']['total_count'];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search