Java RestFB不';Don’不要对帖子发表评论
我用这种方式获取facebook页面上的一些帖子和每条帖子的每条评论:Java RestFB不';Don’不要对帖子发表评论,java,facebook-graph-api,restfb,Java,Facebook Graph Api,Restfb,我用这种方式获取facebook页面上的一些帖子和每条帖子的每条评论: FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN); Connection<Post> pagePosts = facebookClient.fetchConnection("iPhone.page/feed", Post.class); for (List<Post> posts : pagePosts
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
}
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;
}
注释的json部分是:
comments=Comments[count=157 data=[]]
count=157
但如果你现在上那篇帖子,上面写着145。。。而且没有数据
这有什么问题吗?为什么它给我的数据与真实数据不同?我这样解决:
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
}
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;
}
私有静态列表getCommentFromPost(FacebookClient客户端,字符串post\u id){
列表注释=新建ArrayList();
Connection allComments=client.fetchConnection(post_id+“/comments”,Comment.class);
对于(列出后注释:所有注释){
对于(注释:后注释){
long likes=comment.getLikeCount()==null?(comment.getLikes()==null?0:comment.getLikes()):comment.getLikeCount();
comments.add(comment.getMessage()+“-”+likes);
}
}
返回评论;
}
我想访问公共facebook页面,我必须访问\u令牌代码吗?因为对我来说,我的访问令牌代码似乎一次又一次地过期了,所以我必须在第一个代码过期后创建一个新的访问令牌代码来运行程序,你以前有过这样的经历吗?