Question: Using Facebook graph API, I am trying to retrieve number of mutual friends 2 users have. However, I am getting number of friends of one of them instead.

Here is my code:

```
    <?php

    $mutual_array = json_decode(file_get_contents("https://graph.facebook.com/".$fb_id."/mutualfriends/".$other_fb_id."?".$access_token), true);

    $mutual_friends = $mutual_array['data'];
    $mutual_number = count($mutual_friends);

    ?>

```

$mutual\_number gives the number of facebook friends $other\_fb\_id user has. And when I try to print\_r $mutual\_friends it gives all the friends the user has.

Anyone know what's going on here? Thanks.

Answer: 
In your code above $fb\_id must have to be currently login user ID or it must be your application user. Facebook api do not allow to get mutual friends of any x-y-z user until they have joined your application. 

Test it in [fb explorer](https://developers.facebook.com/tools/explorer/?method=GET&path=me/mutualfriends/548573432) 

Alternatively if you have friends of both users you can use [array\_intersect](http://php.net/manual/en/function.array-intersect.php) function of PHP to get common ids from both friends array.

```
$result = array_intersect($user1_friends_array, $user2_friends_array);
print_r($result);

```
You forgot the `access_token=` param:

```
$mutual_array = json_decode(file_get_contents("https://graph.facebook.com/".$other_fb_id."/mutualfriends/".$fb_id."?access_token=".$access_token), true);

```