使用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;
}

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

我的第一个建议:在此处检查基于时间的分页:https://developers.facebook.com/docs/graph-api/using-graph-api

您只需要在fetchConnection呼叫中添加 Parameter.with("since", "<timestamp>")

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

最新更新