我在用着restfb http://restfb.com/以这种方式获取 Facebook 页面的一些帖子和每个帖子的每条评论:
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
Connection<Post> pagePosts = facebookClient.fetchConnection("iPhone.page/feed", Post.class);
for (List<Post> posts : pagePosts)
for (Post post : posts){
for(Comment comment: post.getComments().getData()){
//get number of likes of comment
}
String message = post.getMessage();
String id = post.getId();
long timestamp = post.getCreatedTime().getTime()/1000;
//store info
}
当它获取像这样的帖子时,我的问题就出现了this https://www.facebook.com/130489060322069/posts/422930041125702.
它有 140 条评论,但toString()
方法给了我:
Post[actions=[...] application=null attribution=null caption=techblr.com comments=Comments[count=157 data=[]] createdTime=Wed Feb 27 14:41:58 CET 2013 ....]
评论的json部分是:
comments=Comments[count=157 data=[]]
count=157
但如果你现在继续看那篇文章,它会说 145...而且没有data
!
这可能有什么问题吗?为什么它给我的数据与真实数据不同?
我是这样解决的:
private static List<FBComment> getCommentFromPost(FacebookClient client, String post_id){
List<String> comments = new ArrayList<FBComment>();
Connection<Comment> allComments = client.fetchConnection(post_id+"/comments", Comment.class);
for(List<Comment> postcomments : allComments){
for (Comment comment : postcomments){
long likes = comment.getLikeCount()==null?(comment.getLikes()==null?0:comment.getLikes()):comment.getLikeCount();
comments.add(comment.getMessage()+" - "+likes);
}
}
return comments;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)