Reputation: 79
I am getting NullPointerException while calling getFrom() on commnent comment.getFrom().getId() .... Throws NullPointerException .....
I am using Application Token .....
Obtaining Token
AccessToken accessToken = new DefaultFacebookClient(Version.VERSION_2_8).obtainAppAccessToken(
entry.getValue().getCredential().getAppId(),
entry.getValue().getCredential().getAppSecret());
String token = accessToken.getAccessToken();
Creating Connection and getting Page Feed and Posts
Page page = facebookClient.fetchObject(getPageURL(), Page.class,
Parameter.with("since", sDate),
Parameter.with("until", uDate));
Connection<Post> pageFeed = facebookClient.fetchConnection(page.getId() + "/feed", Post.class,
Parameter.with("limit", 100), Parameter.with("summary", 1),
Parameter.with("since",sDate),
Parameter.with("until",uDate));
Getting Post Details from the Page
Post postDetails = facebookClient.fetchObject(post.getId(),
Post.class,
Parameter.with("fields",
"from,actions,message,story,to,likes.limit(0).summary(true),
comments.limit(0).summary(true),shares.limit(0).summary(true)"));
Getting comments of Post and Calling Comment.getFrom()
Connection<Comment> comments =
facebookClient.fetchConnection(post.getId() + "/comments",
Comment.class,
Parameter.with("limit", 100));
boolean hasNext = true;
while (hasNext && comments.getData().size() > 0) {
for (Comment comment : comments.getData()) {
currentCount++;
currentCommentId=comment.getId();
if (isValidUser(comment.getFrom().getId()) && (!isCommentsSearchEnabled() || filterCommentFeed(comment.getMessage()))) {
writeToSummaryFile(post.getId(), comment, currentCount);
getCommentsOfComment(comment.getId());
}
}
if (comments.hasNext()) {
comments = facebookClient.fetchConnectionPage(comments.getNextPageUrl(), Comment.class);
} else
hasNext = false;
}
Upvotes: 0
Views: 130
Reputation: 1462
You have to specify the fields you like to fetch, so please change
facebookClient.fetchConnection(post.getId() + "/comments",
Comment.class,
Parameter.with("limit", 100));
to
facebookClient.fetchConnection(post.getId() + "/comments",
Comment.class,
Parameter.with("limit", 100), Parameter.with("fields","id,from");
Upvotes: 0