2

我正在使用 Youtube 的 Java API 获取视频的评论。我想知道我能找到所有评论的赞成票或反对票的数量。如果是,那么如何。目前我正在使用下面给出的代码。我正在为每条评论获得totalRating 以找到赞成票,但每次它输出0。我知道这是错误的,但我如何让评论上下投票。任何正确方向的指针将不胜感激。谢谢。

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());
        }
}
4

1 回答 1

1

不幸的是,这些值没有通过 API 公开,也没有添加它们的计划。

于 2012-10-25T21:28:50.343 回答