使用RestFB在帖子中获取用户评论

时间:2017-11-10 14:20:20

标签: java facebook restfb

我在restfb中读到几乎与value相关的主题是null,几乎是错过了Parameter()方法或其他东西。但我的问题不是那些原因。 我不知道为什么我无法在帖子中获得用户评论,结果为空,尽管在Graph API Explorer中我可以得到它。我使用Graph API v2.10,因为v2.11无法获得用户评论。

static AccessToken accessToken = new DefaultFacebookClient(Version.VERSION_2_10).obtainAppAccessToken(Constants.MY_APP_ID,Constants.MY_APP_SECRET);

这是我的代码:

Connection<Comment> commentDetails = facebookClient.fetchConnection(aPost.getId()+ "/comments", Comment.class, 
                        Parameter.with("fields", "message,from{id,name}"));
                if(comments !=null){
                        List<Comment> commentList = commentDetails.getData();
                        System.out.println("---------Comments----------");
                        for(Comment comment : commentList){
                            System.out.println(comment.getMessage() + " - " + comment.getId());
                            System.out.println(" - " + comment.getFrom().getName()); //line 101

                    }

                } 

在控制台中,我看到我可以获得commentIdcommentMessage,但getFrom()为空。

以下是我的输出:

Dear Bill...God blessed you & your family..you are smart & having a lot of money but most importantly you & Melinda has big golden hearts...way to go for helping humans special who they need more..love u & ur family & praying for u all - 10155024059741961_10155024134711961 Exception in thread "main" java.lang.NullPointerException at SimpleMeExample.main(SimpleMeExample.java:101)

0 个答案:

没有答案
相关问题