1
起初:我知道有一些类似的话题,我根据他们编写了一些代码(如下图所示)。我是Facebook api中的新成员,所以我有点失落:D
无论如何,我的应用必须获得所有留言和评论,但我无法全部获得。任何人都可以帮助我吗?这里是我的方法:使用RestFB获取所有留言和评论
public static void getFacebookPosts(String url){
try{
LoggedFacebookClient client = new LoggedFacebookClient();
Page page = client.fetchObject(url, Page.class);
System.out.println(page.getName());
Connection<Post> pageFeed = client.fetchConnection(page.getId() + "/feed", Post.class);
//Getting posts:
for (List<Post> feed : pageFeed){
for (Post post : feed){
//PRINTING THE POST
getAllPostComments(post.getId(), client);
}
}
}catch(com.restfb.exception.FacebookOAuthException ex){
System.out.println("\n!!!!!!! Token Expired !!!!!!!!\n");
}
}
private static void getAllPostComments(String postId, DefaultFacebookClient client){
int currentCount = 0;
JsonObject jsonObject = client.fetchObject(postId + "/comments", JsonObject.class,
Parameter.with("summary", true), Parameter.with("limit", 1));
long commentsTotalCount = jsonObject.getJsonObject("summary").getLong("total_count");
System.out.println("\nComments:");
boolean pom = true;
while(pom == true){ //There should be "while(currentCount < commentsTotalCount)" but currentCount is always < then commentsTotalCount. That's the problem :)
pom = false;
Connection<Comment> comments = client.fetchConnection(postId + "/comments",
Comment.class, Parameter.with("limit", 50000), Parameter.with("offset", currentCount));
for(Comment komentar : comments.getData()){
pom = true;
currentCount++;
stazenychKomentu++;
String mess = komentar.getMessage().replaceAll("\n", " ").replaceAll("\r", " ");
System.out.println(" [" + currentCount + "]: " + komentar.getFrom().getName() + " ## " + mess);
}
}
celkemKomentu += commentsTotalCount;
System.out.println(currentCount + "/" + commentsTotalCount);
}
,这里是我得到的ACCES令牌方式:
public LoggedFacebookClient(){
super();
AccessToken accessToken = this.obtainAppAccessToken(API_KEY, APP_SECRET);
this.accessToken = accessToken.getAccessToken();
}
我会很感激,如果有人可以帮助我。非常感谢,如果我的英语不完美,我会很抱歉。
所以它不可能获得超过200个职位。或者更确切地说,比过去200年更早的帖子? – Ichwardort