java - 如何使用 RestFB 获取评论的回复数

标签 java facebook-graph-api java-8 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() 始终返回 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 - 如何使用 RestFB 获取评论的回复数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45590104/

相关文章:

Java 8 使用Optional 避免空指针检查

php - Facebook 登录无法连接到 graph.facebook.com :443; Operation now in progress

ios - Facebook 登录权限 API

java - 使用 reduce 和 collect 求平均值

java - Eclipse Equinox,如何配置自动加载插件文件夹中的包

facebook - 如何撤销给定的 Facebook token ?

functional-programming - 默认 Stream<E> stream() vs static<T> Stream<T> of(T t)

java - 如何将对象从 Controller 传递到jsp页面,然后迭代该对象以将它们显示在表格中?

java - 我需要为我的类(class)项目创建一个 ArrayList

java - recyclerview 中的 radio 组不正确