Reputation: 1
I am trying to find the friends with most mutual friends with me.
public function topThreeMutualFriends() {
$count;
$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'));
if(!$result)
throw new exception("No Mutual Friends");
else{
foreach ($result as $uid)
$count[$uid['uid1']]++;
arsort($count, SORT_NUMERIC);
$i=0;
foreach($count as $key=>$uid){
$topthree[$i++]=$key;
if($i==3)break;
}
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??
Upvotes: 0
Views: 1498
Reputation: 11852
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';
Upvotes: 4
Reputation: 43816
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.
Upvotes: 1