How to get friends in order of number of mutual friends?
Asked Answered
C

4

5

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?

Crewelwork answered 16/10, 2011 at 8:54 Comment(0)
A
6

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

Adabelle answered 1/5, 2013 at 1:14 Comment(3)
For other noobs: I needed to switch from Graph API to FQL Query for this to work in the explorer. Otherwise I received a "(#601) Parser error: unexpected end of query." error. :)Josh
I think the API has changed. This query now returns { "error": { "message": "(#12) fql is deprecated for versions v2.1 and higher", "type": "OAuthException", "code": 12 } }Tweed
The explorer doesn't seem to show all of my friends. Why not?Melodimelodia
H
2

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.

Hilten answered 16/10, 2011 at 10:12 Comment(0)
N
1

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.

Navada answered 17/10, 2011 at 5:5 Comment(0)
S
0

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.

Serdab answered 28/10, 2015 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.