Youtube api如何得到回复评论和喜欢

时间:2017-08-05 23:10:50

标签: youtube youtube-api comments

使用此

获取评论

评论主题:列表

获取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."
 }
}

但是如何让每个评论回复,并检查用户喜欢与否,知道吗?

2 个答案:

答案 0 :(得分:0)

您可以使用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");

关于喜欢,您可能需要查看snippet.viewerRating

  

观众对此评论的评分。请注意,此属性目前不会识别dislike评级,但此行为可能会发生变化。与此同时,如果观众对评论进行了积极评价,则属性值为like。在所有其他情况下,该值均为无,包括用户已将评论评为否定评级或未对评论进行评分。

     

此属性的有效值为:

     
      
  •   
  •   

然后查看snippet.likeCount以获取评论收到的喜欢总数(正评分)。

此处显示了显示comments资源格式的sample JSON structure

{
  "kind": "youtube#comment",
  "etag": etag,
  "id": string,
  "snippet": {
    ......
    "authorChannelId": {
      "value": string
    },
    ......
    "viewerRating": string,
    "likeCount": unsigned integer,
    ......
  }
}

希望这有帮助!

答案 1 :(得分:0)

根据API Documentation of YouTube,只需要将part参数扩展为replies,如下所示:

https://www.googleapis.com/youtube/v3/commentThreads?part=snippet,replies&videoId=[VIDEO_ID]&key=[YOUR_YOUTUBE_API_KEY]

如果没有视频 ID 和 API 密钥,URL 就没有多大意义,所以我也将这些添加到了上面的示例中。