我正在尝试从youtube视频中提取评论。我能够检索评论(https://developers.google.com/youtube/v3/docs/commentThreads/list#try-it),但我不能确定如何检索单个评论的回复。我查看了Youtube API文档,但不能准确地指出如何检索评论回复。有没有人能告诉我这是不是可能的?如果是,我该怎么做?谢谢。
发布于 2016-07-18 14:01:27
在此documentation中,您可以使用parentId参数,该参数指定应为其检索回复的评论的ID。但需要注意的是,YouTube目前只支持顶级评论的回复,未来可能会支持回复。您可以使用comments.list方法检索评论回复。
示例:
//Call the YouTube Data API's comments.list method to retrieve existing comment replies.
V3CommentListResponse commentsListResponse = youtube.comments().list("snippet")
.setParentId(parentId).setTextFormat("plainText").execute();
List<Comment> comments = commentsListResponse.getItems();
if (comments.isEmpty()) {
System.out.println("Can't get comment replies.");
} else {
// Print information from the API response.
System.out.println("\n===========Returned Comment Replies============\n");
for (Comment commentReply : comments) {
snippet = commentReply.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n---------------\n");
}
Comment firstCommentReply = comments.get(0);
firstCommentReply.getSnippet().setTextOriginal("updated");
Comment commentUpdateResponse = youtube.comments()
.update("snippet", firstCommentReply).execute();
// Print information from the API response.
System.out.println("\n============Updated Video Comment===============\n");
snippet = commentUpdateResponse.getSnippet();
System.out.println(" - Author: " + snippet.getAuthorDisplayName());
System.out.println(" - Comment: " + snippet.getTextDisplay());
System.out.println("\n--------------------------------\n");检查此相关的thread。
发布于 2021-08-06 15:33:56
根据API Documentation of YouTube,您可以通过将值为snippet,replies的参数part添加到commentThreads端点来检索评论和相关回复,如下所示:
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&videoId=[VIDEO_ID]&key=[YOUR_YOUTUBE_API_KEY]上面的示例包含了视频ID和API密钥。
https://stackoverflow.com/questions/38417353
复制相似问题