I am trying to get a list of mutual friends of myself and another user but none of the API I found in the documentation works. Either I get some weird permission errors that I can only get my friends list and no other user or I get the following error:
Fatal error: Call to a member function friends_getMutualFriends() on a non-object in /home/app.php on line 27
Is there a standard way that is used to get the total number of mutual friends or at least the list of friend ids of my friend?
I am trying to get a list of mutual friends of myself and another user but none of the API I found in the documentation works. Either I get some weird permission errors that I can only get my friends list and no other user or I get the following error:
Fatal error: Call to a member function friends_getMutualFriends() on a non-object in /home/app.php on line 27
Is there a standard way that is used to get the total number of mutual friends or at least the list of friend ids of my friend?
Share Improve this question asked Oct 25, 2010 at 0:23 LegendLegend 117k123 gold badges284 silver badges406 bronze badges5 Answers
Reset to default 5This will give a list of mutual friends:
$mutual_friends = $facebook->api('/me/mutualfriends/friendid');
Ok... This one gave me a real hard time. I managed to do this using the Facebook JS SDK. Here's the snippet just in case anyone else wants to do this:
FB.api(
{
method: 'fql.query',
query: 'SELECT id FROM profile WHERE id IN (SELECT uid2 FROM friend WHERE uid1=me())'
},
function(response) {
$.each(response, function(json) {
console.info(response[json].id);
FB.api(
{
method: 'friends.getMutualFriends',
target_uid: 'INSERT ANOTHER FRIEND ID HERE'
},
function(response) {
console.info(response);
}
);
return false;
});
}
);
This is working 2016/ JAN
https://graph.facebook./v2.5/[USER_FRIEND_ID]?limit=100&fields=context.fields(mutual_friends.limit(100))&access_token=[YOUR_USER_TOKEN]
The result is a Json with your mon friends. Working in Graph v2.4 and v2.5 fine.
PS: if you searching for ALL_mutual_friend is friends without the same app instaled Mutual_friends -> booth users you from token session and another one in query have the app autorized.
new field in facebook user.context https://developers.facebook./docs/graph-api/reference/user-context/
(Use Graph Explorer to Test )
I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
Legend
given answer is giving only mutual friends for friend. I have given solution which gives mutual friends of user(friend or friend of friend).
You asked mutual friends of myself and another user
(not only friend) and in PHP.
So below is solution:
$source_id=current user
$target_id=friend or friend of friend
$query="SELECT uid, name, work FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $source_id and uid2 IN (SELECT uid2 FROM friend WHERE uid1 = $target_id) ) ORDER BY name";
$freinds_list=$this->facebook->api(array('method'=>'fql.query',
'query'=>$query));
Well it's actually friends.getMutualFriends().
Have a play here.