0

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??

4

2 回答 2

4

这是相当复杂的代码。为什么不让 FQL 找到您的前三位朋友和最多的共同朋友呢?

$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'; 
于 2012-08-15T16:38:22.810 回答
1

可能的原因是您粘贴的错误消息,就 Facebook 方面所需的资源而言,您的查询过于昂贵。

将其分解为较小的查询并改为这样做。例如,在一次调用中获取朋友列表,将列表拆分为更小的块,并在单独的调用中检查批次的共同朋友计数。

于 2012-08-15T15:38:11.143 回答