我正在尝试使用带有 Java 的 youtube-api 提取对某些 YouTube 视频的评论。一切都很好,除了如果视频有大量评论(它停止在 950 到 999 之间的某个地方),我无法提取所有评论。我正在按照一种简单的方法对 VideoEntry 的 CommentFeed 进行分页,在每个页面上获取评论,然后将每个评论存储在 ArrayList 中,然后再将它们写入 XML 文件。这是我检索评论的代码
int commentCount = 0;
CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
do {
//Gets each comment in the current feed and prints to the console
for(CommentEntry comment : commentFeed.getEntries()) {
commentCount++;
System.out.println("Comment " + commentCount + " plain text content: " + comment.getPlainTextContent());
}
//Checks if there is a next page of comment feeds
if (commentFeed.getNextLink() != null) {
commentFeed = service.getFeed(new URL(commentFeed.getNextLink().getHref()), CommentFeed.class);
}
else {
commentFeed = null;
}
}
while (commentFeed != null);
我的问题是:我可以提取的评论数量是否有限制,或者我做错了什么?
最佳答案
使用/引用这个
String commentUrl = videoEntry.getComments().getFeedLink().getHref();
CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
for(CommentEntry comment : commentFeed.getEntries()) {
System.out.println(comment.getPlainTextContent());
}
如前所述here,每次迭代的最大结果数为 50(似乎)
您可以使用 start-index 检索多个结果集,如前所述 here
关于java - 从 Youtube 中提取的评论数量是否有限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14336803/