2017-04-18 41 views
0

我正在使用RestFB从facebook页面获取帖子。问题是我只想要该页面的最新帖子,比方说,上个月的帖子。使用我的代码,我可以获得所有历史记录,并且需要很长时间。 我该怎么做?我没有阅读关于“时间戳”参数的信息。我已经尝试使用极限参数,但没有很好的结果。使用RestFB获取Facebook的最新帖子

我的代码是:

public static JSONArray GetPostsFromPage(String idpage) { 
    String texto, idpost; 
    Date timestamp; 
    JSONArray array = new JSONArray(); 
    JSONObject objeto; 
    Connection<Post> postFeed = fbClient.fetchConnection(idpage + "/feed", Post.class, Parameter.with("limit", 50)); 

    for (List<Post> postPage : postFeed) { 
     for (Post aPost : postPage) { 
      objeto = new JSONObject(); 
      idpost = aPost.getId(); 
      texto = aPost.getMessage(); 
      timestamp = aPost.getCreatedTime(); 

      objeto.put("id", idpost); 
      objeto.put("texto", texto); 
      objeto.put("timestamp", timestamp); 

      array.put(objeto); 
     } 
    } 
    return array; 
} 

任何想法都会受到欢迎。谢谢。

回答

1

我的第一个建议: 检查的时基分页浏览: https://developers.facebook.com/docs/graph-api/using-graph-api

您只需添加Parameter.with("since", "<timestamp>")给你打电话fetchConnection。

第二个建议: 将循环保留在保存的时间戳上。您只需保存最新帖子的TS,并在下一个轮询迭代中停止该TS上的循环。

相关问题