2017-08-09 77 views
1

我需要獲得有關經過身份驗證的用戶擁有的所有節點的回覆的評論。如何獲得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,即使意見有回覆。

我該如何解決這個問題?提前致謝。

回答

3

更改線路

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領域。

+0

謝謝!!有效 –