gpt4 book ai didi

java - RestFB 不对帖子发表评论

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:55 25 4
gpt4 key购买 nike

我正在使用 restfb以这种方式获取 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 的帖子时,我的问题就出现了.

它有 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... 并且没有数据!

这可能是什么问题?为什么它给我的数据与真实数据不同?

最佳答案

我是这样解决的:

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;
}

关于java - RestFB 不对帖子发表评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15117398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com