I was wanting to find out if it is possible using the Facebook API or Open Graph and two users ID to out put there mutual friends?
As i have managed to do this but it only lists the mutual friends that are ‘playing your game’ not the whole list.
bellow is the function i have created:
function getMutualFriends($facebook, $uid1, $uid2,$amount=3){
$random_ids = array();
try {
$param = array(
'method' => 'friends.getMutualFriends',
'source_uid' => $uid1,
'target_uid' => $uid2,
'callback'=> ''
);
$mutualFriends = $facebook->api($param);
if(count($mutualFriends) < $amount){
$amount = count($mutualFriends);
}
$random = pickrandom($mutualFriends,$amount);
for($i=0; $i<$amount; $i++){
$random_ids[] = get_name($random[$i]);
}
$output = implode(",\n", $random_ids);
print_r($output);
// print_r($mutualFriends);
}
catch(Exception $o) {
print_r($o);
}
// return 'None';
}
The method that you are using (friends.getMutualFriends) is of the REST API which is deprecated:
All you need to know is right there, just use the mutualfriends connection of the User object.
Also, if you want to compare two users who installed your app then you can just get the friends of both users (
USER_ID/friends) and compare yourself.