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?
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
{ "error": { "message": "(#12) fql is deprecated for versions v2.1 and higher", "type": "OAuthException", "code": 12 } }
–
Tweed 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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.
Graph API
toFQL Query
for this to work in the explorer. Otherwise I received a"(#601) Parser error: unexpected end of query."
error. :) – Josh