2

I am trying to get the count of mutual friends between a user and each of his or her friends.

I have looked extensively at the graph api and fql to try and solve this. I have looked at the graph api me/mutualfriends/<uid>

However, if doing this over a large number of friends (>1k) then it is too much to make a request for the mutual friends between each individual friend.

I then tried this with batch requests (max 50 at a time) using both FQL and the Graph API. This still results in one query to get all of the friends, and then N queries for the mutual friends with each individual friend. Even batched 50 at a time, this takes quite a long time.

This is the main FQL query:

select uid1 from friend where uid2 = FRIEND_ID and uid1 in (select uid2 from friend where uid1 = me())';

This is the graph api url:

/me/mutualfriends/FRIEND_ID

I am using batch processing like:

$facebook->api('/?batch='.json_encode($batch), 'POST');

Where each query in the batch is an array like:

$cur = array('method'=>'GET', 'relative_url'=> $relative_url);

Using the graph api instead of fql seems to be faster, but is there a way to get the mutual friends for all the friends in one query? Or is there actually a faster way to do this? I have read about mutual_friend_count at different parts of SO, but have not gotten this to work yet.

jkeesh
  • 3,289
  • 3
  • 29
  • 42

1 Answers1

1

I jut got mutual_friend_count to work as shown here. However, I am still curious if you can construct a single FQL query to get this data.

$fql = "SELECT name,mutual_friend_count FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me())";

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

From Friend with the highest number of mutual friends

Community
  • 1
  • 1
jkeesh
  • 3,289
  • 3
  • 29
  • 42