I\'m trying to get all post messages using restfb, my code is as follows
public Connection publicSearchMessages(Date fromDate, Date toDate) {
Co
There is no way to fetch unlimited results from FB. The default limit is set to 25. As you know, you can change this using the limit
parameter. I have not found an upper border for limit searching the web. Maybe, you can set it to a very high amount.
As I tested recently, You don't have to specify anything. Connection class implements Iterable in this way:
So basically all you need to do is this:
Connection<Post> messages = publicFbClient.fetchConnection("search",
Post.class,
Parameter.with("q", "Watermelon"),
Parameter.with("since", fromDate),
Parameter.with("until", toDate),
Parameter.with("type", "post"));
for (List<Post> feedConnectionPage : messages) {
for (Post post : myFeedConnectionPage) {
// do stuff with post
}
}
If you want to have some kind of method that returns results I would be very careful, because you can be returning thousands of results and crawling through them may take some time (from seconds to minutes or even hours) and result object array is going to be really big. Better idea is to use some asynchronous call and check out results of method periodically.
Though it seems that parameter "since" is ignored. Posts are fetched from newest to oldest and I think that it somehow leave out this parameter when doing paging.
Hope I made it more clear for you :)
Maybe you can try using a loop. FB can't get more than 1000 each time, so you can use the loop to get the whole feeds. Use the offset like this:
Parameter.with("limit", 1000));
Parameter.with("offset", offset));
Offset will be a variable and its value will be 1000,2000,3000...
We have an Iterator object in Post. So we can do it like this:
Connection<Post> messages = publicFbClient.fetchConnection(...) ;
someMethodUsingPage(messages);
while (messages.hasNext()) {
messages = facebookClient.fetchConnectionPage(messages.getNextPageUrl(), Post.class);
someMethodUsingPage(messages);
}
Then in each messages we'll have next 25 messages.