2012-05-09 38 views
1

我想從用戶流中獲取最後10個帖子。出於某種原因,我的FQL查詢會連續返回每個帖子的兩個。這裏是我的代碼,赦免咖啡腳本,Facebook FQL在查詢中返回重複帖子

method = 'fql.multiquery' 
queries = 'feed' : "SELECT attachment , type , created_time , filter_key,  actor_id, description, message FROM stream WHERE (filter_key = 'others' OR filter_key = 'owner') ORDER BY created_time DESC LIMIT 10" 
params = 
    method : method 
    queries : queries 
FB.api (params) , (response) => 
    #and so on 

我不知道爲什麼會發生這種情況。

回答

2

FQL不能分組,並且Facebook以各種方式存儲帖子,所以有「倍數」。要解決這個問題的方法是選擇你所需要的列,並做了「其中」限制你的結果集,即:

select 
    attachment , type , created_time , filter_key, actor_id, description, message 
FROM 
    stream 
WHERE 
    post_id in (select post_id 
     FROM 
     stream 
    WHERE 
      (filter_key = 'others' OR filter_key = 'owner' and created_time < [long-ass unix time]) 
) 
  • 不相信你能做到極限,你應該做的小於/大於日期,或對結果集進行解析和排序
+0

這似乎不起作用。我得到了「(#601)解析器錯誤:意外的')'在250位。」當試圖在Graph API Exporer中運行此查詢時。該錯誤似乎與子查詢有關。 –

+0

實際上看起來就像你在最後有一個額外的右括號。 –

+0

另外「created_date」應該是「created_time」。做出這兩個調整並添加時間戳後,查詢的工作非常好。謝謝(你的)信息。 –