1
votes

I know it's possible to get all posts from a users wall or a users feed But I can't understand how to get all posts from a specific page like "Coca-Cola" in a specific time duration using RestFB. Example: I want to get all post between Date: 1/1/2014 to Date: 15/1/2014

Please Help.

1

1 Answers

0
votes

Getting page posts using the fetchConnection API ("page_id/posts") is not trivial when you want to restrict it by start and end time.. the best way to do so is by using fql query. something along the lines of below code snippet works.

    String query = "select post_id, created_time from stream where "
            + "source_id = " + pageId + " and created_time > " 
            + startTimeInSec + " and created_time < " + endTimeInSec 
            + " limit 500";
    FacebookClient fbClient = new DefaultFacebookClient(accessToken);
    List<FqlPost> fqlPosts = fbClient.executeFqlQuery(query, FqlPost.class);
    for (FqlPost pagePost : fqlPosts) {            
        System.out.println(pagePost);
    }

public static class FqlPost {
    @Facebook("post_id")
    String post_id;

    @Facebook("created_time")
    String created_time;

    @Override
    public String toString() {
        return String.format("%s,%s", post_id, created_time);
    }
}