How to get mutual friends in facebook


facebook Sometimes you may need to retrieve mutual friends between 2 facebook users. Then using this simple api call you can retrieve the mutual friends list. friends.getMutualFriends is a legacy api. But you can easily call this method using php-sdk legacy api calling system.

function getMutualFriends($facebook, $uid1, $uid2){
    try {
        $param  =   array(
                    'method'  => 'friends.getMutualFriends',
                    'source_uid'    => $uid1,
                    'target_uid'  => $uid2,
                    'callback'=> ''
                );
        $mutualFriends   =   $facebook->api($param);
        return $mutualFriends;
    }
    catch(Exception $o) {
        //print_r($o);
    }

    return '';
}
mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

12 Comments

  • VXG
    August 2, 2010 at 11:19 am

    Its really good, I tried for my company’s accounts. Thanks.

  • mctaco
    September 9, 2010 at 7:31 am

    hi, does it require extended permissions to do this? thanks

    • mctaco
      September 9, 2010 at 8:02 am

      Ok it finally worked for me thanks! Source is the user that has the session token, destination the one you want to compare with. You do not need extended permissions and you get back an array with the user ids who are mutual friends. Thanks again!

    • mahmud ahsan
      mahmud ahsan
      September 12, 2010 at 11:23 pm

      No

  • Kishan
    September 14, 2010 at 8:20 pm

    Can you use this for pages?

    • mahmud ahsan
      mahmud ahsan
      September 14, 2010 at 8:24 pm

      It will work for logged in user, i think its possible for page app also

      • Kishan
        November 30, 2010 at 8:42 am

        How can I implement this with the Javascript SDK?

  • khandownloads
    September 28, 2010 at 1:52 pm

    Hi,

    In FBML mode the application is displaying both name and pics of my friends who is using my app.Now I want to display the in iframe mode. I am getting errors saying fb:profilepic and fb:name are not recognizing tags when i used fb:serverFBml tag also. Please help me regarding this..

    Thanks..

    • mahmud ahsan
      mahmud ahsan
      September 28, 2010 at 4:05 pm

      You have to load javascript sdk to parse XFBML tags.

  • Andrei
    November 18, 2010 at 12:24 am

    hey, thanks for the code.
    I have one question though: when I call the function, what does $facebook stand for?

    • mahmud ahsan
      mahmud ahsan
      November 18, 2010 at 12:16 pm

      Checkout my other tutorial to know what is $facebook.

  • manu
    December 9, 2010 at 2:41 pm

    I am trying to embed flash in php…..how will i get the source of videos that are published or shared by my friends that saw in my updates using facebook api?

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage