3

私は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            
    }

私の問題は、このような投稿を取得するときに発生します。

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

それについての問題は何でしょうか?なぜ実際のデータとは異なるデータが得られるのですか?

4

1 に答える 1

5

私はこのように解決しました:

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;
}
于 2013-02-28T00:39:48.010 に答える