Question

/* make the API call */
FB.api(
    "/me/friends",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);

From this code, how do I get the number of the list? I'm interested of getting the total number of friends from a user that use my app.

Was it helpful?

Solution 2

The friends array is in response.data. To get the length of the array, just use response.data.length

See How to loop through me/friends and assign each user it's picture from {USERID}/picture from FB.api

/* make the API call */
FB.api(
    "/me/friends",
    function (response) {
      if (response && !response.error) {
        console.log('Friend count = ', response.data.length);
      }
    }
);

[1]:

OTHER TIPS

Juan is mostly correct.

The only thing I would also recommend is setting the limit to something greater than what you'd expect or walk across the paging:next url.

"paging": {
    "next": "https://graph.facebook.com/xxxxxx/friends?limit=5000&offset=5000&__after_id=xxxxxx"
  }

The default limit is 5000 and while this would usually not be a problem for normal users, celebrities, businesses, etc might have more friends that this.

/friends?limit=10000000000
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top