4

How can I check for the relation between two facebook ids.? i.e friend, friend of friend or there is no relation. By fql or graph api methods(anything).

I know how to get the friend list, mutual friends of facebook id. But I want a proper method which can give the relation between two Facebook ids. I have Googled a lot but didn't get anything related to my problem.

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226

2 Answers2

1
 SELECT uid2 FROM friend WHERE uid1 = me() AND uid2 = {YOUR_FRIEND2_ID}

With this FQL query you can check if give ID is a friend of currently logged in user. It'll return an empty array if given users are not friends. Facebook does not give you friends of a friend, so you can't go beyond the logged in user.

To read the friend table you need any valid access_token to retrieve friends of the current session user

This is the only user that this table can be queried for, the friends of friends cannot be retrieved.

Facebook offical documentation on friend FQL table

Henrik Peinar
  • 2,181
  • 18
  • 22
  • Sorry I can check friend of friend by fql query(app users). I want to check by any simple method. We can get friend of friend which are app users. – Somnath Muluk Feb 28 '12 at 14:13
1

I got solution by checking with fql queries.

//$target_id=id of user to check relationship
//$source_id=logged in user

    $query="SELECT uid, name, work FROM user WHERE uid IN 
    (SELECT uid2 FROM friend WHERE uid1 = $target_id AND uid2=$source_id)
     ORDER BY name";

    $user_info=$this->facebook->api(array('method'=>'fql.query',
                                'query'=>$query));


    if(!empty($user_info)) 
    {
          $degree='friend';
    }
    else {
        $query="SELECT uid, name, work FROM user WHERE uid IN 
       (SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM friend WHERE uid1 = $target_id) AND uid2=$source_id) 
        ORDER BY name";

       $user_info=$this->facebook->api(array('method'=>'fql.query',
                                    'query'=>$query));

    // we can check friend-of-friend for app user friends

       if(!empty($user_info)) {
           $degree='friend-of-friend'; 
       }
    else{
    $degree='none';
    }
    }

Please answer if anyone knows any simple method.

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226