首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检索Youtube评论回复

检索Youtube评论回复
EN

Stack Overflow用户
提问于 2016-07-17 10:27:10
回答 2查看 1.1K关注 0票数 2

我正在尝试从youtube视频中提取评论。我能够检索评论(https://developers.google.com/youtube/v3/docs/commentThreads/list#try-it),但我不能确定如何检索单个评论的回复。我查看了Youtube API文档,但不能准确地指出如何检索评论回复。有没有人能告诉我这是不是可能的?如果是,我该怎么做?谢谢。

EN

回答 2

Stack Overflow用户

发布于 2016-07-18 14:01:27

在此documentation中,您可以使用parentId参数,该参数指定应为其检索回复的评论的ID。但需要注意的是,YouTube目前只支持顶级评论的回复,未来可能会支持回复。您可以使用comments.list方法检索评论回复。

示例:

代码语言:javascript
复制
//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

票数 1
EN

Stack Overflow用户

发布于 2021-08-06 15:33:56

根据API Documentation of YouTube,您可以通过将值为snippet,replies的参数part添加到commentThreads端点来检索评论和相关回复,如下所示:

代码语言:javascript
复制
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&videoId=[VIDEO_ID]&key=[YOUR_YOUTUBE_API_KEY]

上面的示例包含了视频ID和API密钥。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38417353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档