2013-02-12 114 views
1

我試圖從Facebook頁面獲取所有帖子和評論。 這工作挺好的,到目前爲止使用下面的FQL:從Facebook頁面獲取所有帖子和評論

{'all_posts': 
'SELECT created_time, post_id, actor_id, message, description, comments FROM stream 
    WHERE source_id=PAGE_ID ORDER BY created_time', 
'comments': 
    'SELECT id, fromid, post_fbid, text, time, post_id FROM comment WHERE post_id 
    IN (SELECT post_id FROM #all_posts) ORDER BY post_id' 
} 

我試圖使用RestFB圖書館,但我得到

com.restfb.exception.FacebookResponseStatusException: Received Facebook error response 
(code 601): Parser error: unexpected '{' at position 0. 

當我嘗試執行查詢:

List<JsonObject> queryResults = facebookClient.executeQuery(query, JsonObject.class); 

我該如何解決這個問題?

在此先感謝。

+0

描述什麼是你的查詢要傳遞到'executeQuery()'? – robonerd 2013-02-12 23:19:35

+0

我通過了上述「下面的fql」後面提到的查詢來執行查詢。這就是錯誤,因爲現在我發現了,我必須使用Multiquery-Support。我會立即發佈工作代碼作爲回答。 – 2013-02-12 23:24:57

+1

我稍後會回答,因爲我必須等待8個小時,直到允許我回答。 – 2013-02-12 23:34:25

回答

0

我認爲這是RestFB方面的錯誤,解析結果JSON,因爲我得到了幾個異常,有點困惑。

做到這一點,正確的方法是使用RestFB的Multiquery支持(Executing Multiqueries with RestFb

Map<String, String> queries = new HashMap<String, String>(); 
queries.put("all_posts", "select created_time, post_id, actor_id, message, description, comments from stream where source_id=279947942083512 ORDER BY created_time"); 
queries.put("comments", "SELECT fromid, username, text, time, post_id FROM comment WHERE post_id in (SELECT post_id FROM #all_posts) ORDER BY post_id"); 

MultiqueryResults queryResults = facebookClient.executeMultiquery(queries, MultiqueryResults.class); 

,你必須提供MultiqueryResults豆爲1

+0

有人可以爲這些查詢做一個MultiqueryResults Bean的例子嗎? :) – JackTurky 2013-02-27 16:54:35

+0

public class PostsAndCommentsMultiqueryResults { \t @Facebook(「all_posts」) \t private list posts; \t \t @Facebook \t private List comments; \t public list getPosts(){ \t \t return posts; \t} \t公開名單 getComments(){ \t \t返回評論; \t} \t \t } – 2013-02-27 20:34:43

+1

您必須爲StreamComment和StreamPost創建Bean。你不能使用RestFB的Post-Class,因爲它是爲Graph API – 2013-02-27 20:36:06

相關問題