mix
mix

Reputation: 7151

How to Page Through Facebook Graph API Friend List Results for More Than 19 Friends?

I'm trying to page through all Facebook friend list results using the Graph API so I can get a count of all friends for a user (me, right now). I'm using the Graph API Explorer to test, but have also tried it with straight URL-based queries.

For example, I can start the process with a query like:

https://graph.facebook.com/v2.0/me/friends?limit=5000&offset=0&access_token=MYTOKEN

This gives me 19 results and a next page link. If I click/enter the next page link, it gives an empty data array (even though I have hundreds of friends).

When I play with limit and offset, they usually don't behave as expected. A working example is if I ask a limit=10 and offset=10. If I do that, it will give me the second half of the original list.

But as soon as I increase offset above 19 I get an empty data array.

It's as if I only have 19 friends.

How can I get more than 19 friends from the Graph API?

Upvotes: 0

Views: 949

Answers (2)

Andrew.T
Andrew.T

Reputation: 420

Change the API version to 1.0 then you can query friend list successful.

/v1.0/me?fields=friends

Upvotes: 0

C3roe
C3roe

Reputation: 96151

Actually, the context fields seems to work here. It’s main purpose is to show you how many friends the current user and another user have in common – but if you query it for the current user (/me), it seems to show the count of all of the current user’s friends. (Makes sense, kinda – I have all of my friends “in common” with myself …)

/2.0/me?fields=context

will give you a structure of the following format,

{
  "context": {
    "mutual_friends": {
      "data": [
        {
          "id": "…",
          "name": "…"
        },
        {
          "id": "…",
          "name": "…"
        },
        …
      ],
      "paging": {
        "cursors": {
          "before": "…",
          "after": "…"
        }
      },
      "summary": {
        "total_count": 1234
      }
    },

The total_count under summary seems to be your total number of friends.

Upvotes: 1

Related Questions