【问题标题】:Get only latest posts of Facebook using RestFB使用 RestFB 仅获取 Facebook 的最新帖子
【发布时间】:2017-04-18 18:58:09
【问题描述】:

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

欢迎任何想法。谢谢。

【问题讨论】:

    标签: java facebook facebook-graph-api restfb


    【解决方案1】:

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

    您只需将Parameter.with("since", "&lt;timestamp&gt;") 添加到您的 fetchConnection 调用中。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多