2012-08-15 162 views
0

我想找到與我最共同的朋友的朋友。Facebook最共同的朋友

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);} 
    } 

在上面的代碼拋出一個異常,指出:「這個API調用無法完成,由於資源限制」 我試圖讓所有的權限,查詢工作在FQL測試儀的罰款。 可能是什麼原因?

回答

1

可能的原因是您粘貼的錯誤消息,您的查詢在Facebook所需的資源方面太昂貴。

將其分解爲更小的查詢,然後執行此操作。例如,在一次呼叫中獲取朋友列表,將列表分成更小的塊,並檢查共同朋友計數分批呼叫中的批次。

+0

是的,這是完全正確的。我們有同樣的問題。具有> 100人的子選擇導致facebook經常只是放棄的負載。你需要將請求分割成幾部分,然後批處理,fql mutli查詢它們或者迭代循環。 – trcarden 2012-11-13 19:46:05

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';