2017-08-09 1 views
1

Ich muss die Kommentare mit Ihren Antworten für alle Knoten von authentifizierten Benutzern besitzen.Wie bekomme ich die Anzahl der Antworten von einem Kommentar mit RestFB

Ich habe es in der folgenden Art und Weise mit Strom 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)); 
    } 

ich die zweite flapMap optimieren müssen, die einen Strom mit dem Top-Level-Kommentar und ihren Antworten schafft.

Klar wäre es, dies zu tun:

.flatMap(comment -> comment.getCommentCount() > 0 ? StreamUtils.concat(
      getCommentsByObjectAfterThan(facebookClient,comment.getId(), startDate, user), comment) : Stream.of(comment)) 

Das Problem ist, dass es comment.getCommentCount() immer 0 zurück, obwohl die Kommentare haben Antworten.

Wie kann ich das beheben? Danke im Voraus.

Antwort

3

Ändern Sie die Zeile

Connection<Comment> commentConnection 
      = facebookClient.fetchConnection(objectId + "/comments", Comment.class); 

zu

Connection<Comment> commentConnection 
      = facebookClient.fetchConnection(objectId + "/comments", Comment.class, Parameter.with("fields","comment_count"); 

Dann erhalten Sie das comment_count Feld des Kommentars.

+0

Danke !!. Es funktionierte –

Verwandte Themen