0

Possible Duplicate:
Get a list of Friends of a Friend on facebook

I need to get the count of someone's friends (1 level), the friends of their friends (2 levels), and the friends of the friends of their friends (3 levels). Is this possible with FQL or the Graph API, and if so, how?

So far, I know that I can get the first level counts with this FQL query:

SELECT friend_count FROM user WHERE uid = me()

but I'm not sure how to get any further, or even if it is possible to do so.

Community
  • 1
  • 1
Marcelo Mason
  • 6,750
  • 2
  • 34
  • 43

1 Answers1

6

No, this can't be done using the Graph API or FQL. The furthest you can get is to select information from the user table relating to your friends, such as their friends count, by doing a subselect in your query like this:

SELECT uid, friend_count
FROM user
WHERE uid IN (
    SELECT uid1
    FROM friend
    WHERE uid2 = me()
)

but that doesn't even get you to 2 levels in your original question, because many of those friends of yours will have friends in common, and so the sum of those counts will be vastly more than the number of friends of friends you have. In order to get the information you need, what you would need to do is pull out a list of ids of friends of friends and then count them yourself by executing a query like this

SELECT uid1
FROM friend
WHERE uid2 in (
    SELECT uid1
    FROM friend
    WHERE uid2 = me()
)

However, if you try to execute this, you'll get an error that looks something like:

{
  "error": {
    "message": "Can't lookup all friends of 36807322. Can only lookup for the logged in user or the logged in user's friends that are users of your app.", 
    "type": "NoIndexFunctionException", 
    "code": 604
  }
}

and if you try to query your friends' friend lists one by one on the Graph API, you'll get the same error message, as described here (thanks Igy for this link).

Consequently, there is no way whatsoever to do what you want to do using the existing APIs (unless, of course, you get a sufficiently massive user-base for your Facebook app that you can incrementally construct a graph of the user's friends of friends using access tokens for a multitude of other users of your app - but I assume that such a 'solution' is not helpful to you!)

Mark Amery
  • 143,130
  • 81
  • 406
  • 459