1

I'm trying to fetch all the posts and comments from a Facebook Page. This works quite good so far using the following FQL:

{'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'
}

I'm trying to use the RestFB Library, but I get

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

when I try to execute the query:

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

How can I solve this issue?

Thanks in advance.

Jan B
  • 518
  • 1
  • 3
  • 18
  • What is your query that you are passing to `executeQuery()`? – robonerd Feb 12 '13 at 23:19
  • I passed the query mentioned after "the following fql" above to execute Query. And that was the mistake, because , as I found out now, I have to use the Multiquery-Support. I'll post the working code as answer right away. – Jan B Feb 12 '13 at 23:24
  • 1
    I'll answer it later, because I have to wait 8 hours until I'm allowed to answer. – Jan B Feb 12 '13 at 23:34

1 Answers1

0

I thought it was a mistake on RestFB side, parsing the result json, because I got several Exceptions and was kind of confused.

The right way to do this is to use the Multiquery Support of RestFB (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);

You have to provide the MultiqueryResults Bean as described in 1

Jan B
  • 518
  • 1
  • 3
  • 18
  • can someone make an example of MultiqueryResults Bean for these queries? :) – Jayyrus Feb 27 '13 at 16:54
  • public class PostsAndCommentsMultiqueryResults { @Facebook("all_posts") private List posts; @Facebook private List comments; public List getPosts() { return posts; } public List getComments() { return comments; } } – Jan B Feb 27 '13 at 20:34
  • 1
    you have to create beans for StreamComment and StreamPost. You cant use the Post-Class from RestFB, because it is for the Graph API – Jan B Feb 27 '13 at 20:36
  • oh, thank you very much! i was trying graph api with RestFB to do the same work but it doesn't work very well... if you know something can you take a look at http://stackoverflow.com/questions/15117398/restfb-doesnt-give-comments-of-post pls? :) – Jayyrus Feb 28 '13 at 00:01