当我尝试获取用户使用Facebook4j流播放在墙上的所有Facebook帖子时,我似乎只能获得过去14天的帖子。有没有办法绕过这个限制并让用户在墙上发布的每条消息?
我正在使用分页,并且在过去的两周内收到了550封邮件,但没有更多。
这是我的代码
private void printFBMessages(FileWriter fileWriter, String nameFeed)
throws InterruptedException, IOException, FacebookException {
int n = 0;
boolean notEmpty = true;
while (notEmpty) {
try {
notEmpty = false;
System.out.println("N: " + n);
for (Post post : facebook.getFeed(nameFeed, new Reading().limit(100).offset(n))) {
notEmpty = true;
MessageInfo msg = new MessageInfo();
msg.setDate(post.getCreatedTime().toString());
msg.setTitle(post.getMessage());
System.out.println(msg);
n++;
addControleToResult(fileWriter, nameFeed, msg);
}
if (!notEmpty) {
System.out.println("Empty");
}
} catch (FacebookException ex) {
System.out.println(ex.getMessage());
Thread.sleep(300000);
}
n++;
}
System.out.println("Done!");
return;
}
答案 0 :(得分:0)
似乎我正在处理分页错误,这就是为什么它没有按预期工作的原因。
这是实际按预期工作的代码示例:
private void printFBMessages(FileWriter fileWriter, String nameFeed)
throws InterruptedException, IOException, FacebookException {
boolean notEmpty = true;
facebook4j.ResponseList<Post> posts = facebook.getFeed(nameFeed, new Reading().limit(100));
while (notEmpty) {
try {
notEmpty = false;
for (Post post : posts) {
notEmpty = true;
MessageInfo msg = new MessageInfo();
msg.setDate(post.getCreatedTime().toString());
msg.setTitle(post.getMessage());
System.out.println(msg);
addControleToResult(fileWriter, nameFeed, msg);
}
posts = facebook.fetchNext(posts.getPaging());
} catch (FacebookException ex) {
System.out.println(ex.getMessage());
Thread.sleep(300000);
}
}
System.out.println("Done!");
return;
}