2012-10-25 9 views
2

我使用Youtube的Java API獲取視頻的評論。我想知道我是否可以找到所有評論的最高票數或最低票數。如果是,那麼如何。目前我正在使用下面給出的代碼。我得到totalRating爲每個評論找到upvotes,但每次它輸出0.我知道這是錯誤的,但我怎麼得到投票上下注釋。任何指針在正確的方向將不勝感激。謝謝。如何查找投票數量或通過API投票下來的YouTube的意見

private void AddComments(YouTubeVideo ytv,VideoEntry videoEntry,YouTubeService service) 
{  
     try 
     { 
     //Get Comments     
     String commentUrl = videoEntry.getComments().getFeedLink().getHref();  

     LinkedList<YouTubeComment> commentsLinkedList = new LinkedList<YouTubeComment>(); 
     if(commentUrl!= null && commentUrl.length() > 0) 
     { 
       CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class); 

       if(commentFeed != null) 
       { 

        for(CommentEntry comment : commentFeed.getEntries()) 
        { 
         YouTubeComment youtubeComment = new YouTubeComment(); 

         if(comment.getTotalRating()!=null) 
         **//comment.getTotalRating() is always equal to 0.** 
         youtubeComment.setLike(comment.getTotalRating()); 
         else 
          youtubeComment.setLike(0); 

         youtubeComment.setSpamStatus(comment.hasSpamHint()); 
         String commentinVideo = comment.getPlainTextContent(); 
         if(commentinVideo != null) 
          youtubeComment.setComment(comment.getPlainTextContent()); 
         else 
          youtubeComment.setComment(" "); 

         commentsLinkedList.add(youtubeComment); 
        } 
        ytv.setComments(commentsLinkedList); 
       } 
       else 
        ytv.setComments(commentsLinkedList);    
     } 
     else 
     { 
       ytv.setComments(commentsLinkedList); 
     } 

     }    
     catch(Exception ex) 
     { // This means that "Comments are disabled for this video." 
      LinkedList<YouTubeComment> comments = new LinkedList<YouTubeComment>(); 
      ytv.setComments(comments); 

      System.out.println("Could not add comments for video := " + videoUrl); 
      System.out.println("This happens when comments are disabled for the video"); 
      System.out.println("Exception in function AddComments : " + ex.toString()); 
     } 
} 

回答

1

不幸的是,這些值不通過API公開,也沒有計劃添加它們。