gpt4 book ai didi

java - 如何通过 API 查找 youtube 评论的投票数

转载 作者:行者123 更新时间:2023-11-30 11:39:48 26 4
gpt4 key购买 nike

我正在使用 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());
}
}

最佳答案

遗憾的是,这些值未通过 API 公开,并且没有添加它们的计划。

关于java - 如何通过 API 查找 youtube 评论的投票数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13071362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com