2017-04-18 70 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上的循環。

相關問題