Java 使用RestFB仅获取Facebook的最新帖子
我正在使用RestFB从facebook页面获取帖子。问题是我只想要页面上最新的帖子,比如说,上个月的帖子。用我的代码,我得到了所有的历史,这需要很多时间。 我该怎么做?我还没有读过“timestamp”参数。我尝试了极限参数,但没有得到好的结果 我的代码是:Java 使用RestFB仅获取Facebook的最新帖子,java,facebook,facebook-graph-api,restfb,Java,Facebook,Facebook Graph Api,Restfb,我正在使用RestFB从facebook页面获取帖子。问题是我只想要页面上最新的帖子,比如说,上个月的帖子。用我的代码,我得到了所有的历史,这需要很多时间。 我该怎么做?我还没有读过“timestamp”参数。我尝试了极限参数,但没有得到好的结果 我的代码是: public static JSONArray GetPostsFromPage(String idpage) { String texto, idpost; Date timestamp; JSONArray a
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;
}
publicstaticjsonarray GetPostsFromPage(stringidpage){
字符串texto,idpost;
日期时间戳;
JSONArray数组=新的JSONArray();
JSONObject对象对象;
Connection postFeed=fbClient.fetchConnection(idpage+“/feed”,Post.class,Parameter.with(“limit”,50));
对于(列表后页:postFeed){
对于(后代理:后页){
objeto=新的JSONObject();
idpost=aPost.getId();
texto=aPost.getMessage();
timestamp=aPost.getCreatedTime();
objeto.put(“id”,idpost);
把(texto),texto;
放置(“时间戳”,时间戳);
数组.put(objeto);
}
}
返回数组;
}
任何想法都会受到欢迎。谢谢。我的第一个建议:
在此处检查基于时间的分页:
您只需向您的连接调用添加参数
第二项建议:
将循环保留在保存的时间戳上。您只需保存最新帖子的TS,并在下一次轮询迭代中停止该TS上的循环