如何使用 RestFB 从评论中获取回复数
How to get the number of replies from a comment with RestFB
我需要获得您对经过身份验证的用户拥有的所有节点的回复的评论。
我通过以下方式使用流 java 8:
private Stream<Comment> getCommentsByObjectAfterThan(final FacebookClient facebookClient, final String objectId, final Date startDate, User user) {
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class);
return StreamUtils.asStream(commentConnection.iterator())
.flatMap(List::stream)
.flatMap(comment
-> StreamUtils.concat(
getCommentsByObjectAfterThan(facebookClient, comment.getId(), startDate, user), comment)
)
.filter(comment -> !comment.getFrom().getId().equals(user.getId()) &&
(startDate != null ? comment.getCreatedTime().after(startDate) : true));
}
我需要优化第二个 flapMap,它使用顶级 评论及其回复.
创建流
显然它必须这样做:
.flatMap(comment -> comment.getCommentCount() > 0 ? StreamUtils.concat(
getCommentsByObjectAfterThan(facebookClient,comment.getId(), startDate, user), comment) : Stream.of(comment))
问题是它 comment.getCommentCount()
总是 returns 0 即使评论有回复。
我该如何解决这个问题?提前致谢。
换行
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class);
至
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class, Parameter.with("fields","comment_count");
然后得到评论的comment_count
字段
我需要获得您对经过身份验证的用户拥有的所有节点的回复的评论。
我通过以下方式使用流 java 8:
private Stream<Comment> getCommentsByObjectAfterThan(final FacebookClient facebookClient, final String objectId, final Date startDate, User user) {
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class);
return StreamUtils.asStream(commentConnection.iterator())
.flatMap(List::stream)
.flatMap(comment
-> StreamUtils.concat(
getCommentsByObjectAfterThan(facebookClient, comment.getId(), startDate, user), comment)
)
.filter(comment -> !comment.getFrom().getId().equals(user.getId()) &&
(startDate != null ? comment.getCreatedTime().after(startDate) : true));
}
我需要优化第二个 flapMap,它使用顶级 评论及其回复.
创建流显然它必须这样做:
.flatMap(comment -> comment.getCommentCount() > 0 ? StreamUtils.concat(
getCommentsByObjectAfterThan(facebookClient,comment.getId(), startDate, user), comment) : Stream.of(comment))
问题是它 comment.getCommentCount()
总是 returns 0 即使评论有回复。
我该如何解决这个问题?提前致谢。
换行
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class);
至
Connection<Comment> commentConnection
= facebookClient.fetchConnection(objectId + "/comments", Comment.class, Parameter.with("fields","comment_count");
然后得到评论的comment_count
字段