Facebook Most Mutual Friends

I am trying to find the friends with most mutual friends with me.

public function topThreeMutualFriends() {
    $query='select uid1 from friend where uid1 in (select uid2 from friend where uid1=me()) and uid2 in (Select uid2 from friend where uid1=me()) and uid1!=uid2';
    $result = $this->api(array('query' => $query , 'method' => 'fql.query'));
        throw new exception("No Mutual Friends");
        foreach ($result as $uid)
        arsort($count, SORT_NUMERIC);
        foreach($count as $key=>$uid){
    return array($topthree,$count);}

In the above code an exception is raised stating:"This API call could not be completed due to resource limits" I tried giving all the permissions, and the query works fine in the fql tester. What could be the possible reason??


That's pretty complex code. Why not just let FQL find your top three friends with the most mutual friends?

$query = 'SELECT uid, name, mutual_friend_count 
          FROM user WHERE uid IN 
            (SELECT uid1 FROM friend WHERE uid2 = me()) 
          ORDER BY mutual_friend_count DESC LIMIT 3'; 

The possible reason is the error message you pasted, your query is too expensive in terms of the resources needed from Facebook's side.

Break it up into smaller queries and do that instead. For example, fetch the list of friends in one call, split the list into smaller chunks, and check the mutual friends count for the batches in separate calls.

Need Your Help

Java Enum without encapsulating it in a class

java enums

I have a situation where I need the Checker enum below used in multiple classes: