Kristen Harrison
Kristen Harrison

Reputation: 61

How to get friends in order of number of mutual friends?

I am developing a Facebook application. I want to know how I can get friends in the order of number of mutual friends. Is it possible with FQL or any other method?

Upvotes: 5

Views: 6390

Answers (4)

majick
majick

Reputation: 319

This is only a partial answer as they are not all in one place, still haven't found a way to get them on one page yet, but it is a start, could be run in a loop programmatically through your friend list...

https://www.facebook.com/browse/mutual_friends/?uid=xxxxxxxxxxxx

because if you don't give a uid it returns an error... I was just trying to get a list of all my friends on one pagem, but no dice. ridonculous.

Upvotes: 0

Moustafa Samir
Moustafa Samir

Reputation: 2268

Update

I can't find a way to do it in one request using graph API but it can be done in Ruby by getting friends list then sending request for each friend using User context like this example

Original answer

Here is the FQL query to be used Which is working only for api versions < v2.1

SELECT uid, mutual_friend_count from user where uid in (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count desc

you can try it in the explorer

https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20uid%2C%20mutual_friend_count%2C%20friend_count%20from%20user%20where%20uid%20in%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%29%20ORDER%20BY%20mutual_friend_count%20desc

Upvotes: 6

bkaid
bkaid

Reputation: 52063

I don't think mutual friends are available via FQL so you would have to do this the hard: calling the graph api in a loop for each friend and getting a count of mutual friends. The graph api method is: /me/mutualfriends/yourFriendsId and you could do 20 batch requests at a time to help speed this up. If you can find a way to do this with FQL, that would be your fastest route.

Upvotes: 1

Salman
Salman

Reputation: 3726

Theoretically, you can get a list of a user's friends using:

$friendsOfFriend = $facebook->api('/'.$yourFriendsFacebookId.'/friends');

Then you can check each of the result to see if they are your friend too.

$isMyFriend = $facebook->api('/me/friends/'.$someonesFacebookId);

... and keep a track of the count.

However my test didn't return any result yet. I attempted to get the friends of some of my facebook friends but it returns an exception: Can't lookup all friends of {friend's_facebook_ID}. Can only lookup for the logged in user {my_facebook_ID}, or friends of the logged in user with the appropriate permission. So there might be permission issue here.

Upvotes: 2

Related Questions