youtube - YouTube API如何获得评论和喜欢的回复

标签 youtube youtube-api comments

使用此获取评论

评论主题:列表

GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

但是,如何知道每个评论的答复并检查用户是否喜欢?

最佳答案

您可以使用 comments.list method来获取评论回复。这是一个example:

// Call the YouTube Data API's comments.list method to retrieve
// existing comment
// replies.
               CommentListResponse 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");

关于喜欢,您可能要 checkout snippet.viewerRating

The rating the viewer has given to this comment. Note that this property does not currently identify dislike ratings, though this behavior is subject to change. In the meantime, the property value is like if the viewer has rated the comment positively. The value is none in all other cases, including the user having given the comment a negative rating or not having rated the comment.

Valid values for this property are:

  • like
  • none


然后检查 snippet.likeCount 以获取评论已收到的点赞总数(积极评分)。

这是sample JSON structure,它显示comments资源的格式。
{
  "kind": "youtube#comment",
  "etag": etag,
  "id": string,
  "snippet": {
    ......
    "authorChannelId": {
      "value": string
    },
    ......
    "viewerRating": string,
    "likeCount": unsigned integer,
    ......
  }
}

希望这可以帮助!

关于youtube - YouTube API如何获得评论和喜欢的回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45527147/

相关文章:

youtube - 查找带有字幕的特定语言的随机youtube视频

html - 将响应式 youtube iframe 嵌入页面中心

javascript - 为什么 YouTube iframe 播放器在加载时不调用 onYouTubePlayerReady?

bash - 使用 sed 检索和修改文件中的单行

MySQL Workbench 6.2 在创建 View 后删除了我的所有评论

java - 如何显式注释空方法?

java - YouTube Player崩溃(java.lang.NullPointerException,空对象引用)

android - 在Android上的HTML中嵌入youtube视频只有声音,没有视频

youtube - 视频代码:静音和自动播放

android - 每2或3秒钟YouTube视频暂停