优酷 api 如何获得对评论和喜欢的回复



使用这个获取评论

评论线程:列表

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

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

根据 YouTube 的 API 文档,只需要用replies扩展part参数,如下所示:

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

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

您可以使用comments.list方法来检索评论回复。下面是一个示例:

// 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。在所有其他情况下,该值均为 none,包括用户对评论进行了负面评级或未对评论进行了评级。

此属性的有效值为:

  • 喜欢
  • 没有

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

下面是显示comments资源格式的示例 JSON 结构。

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

希望这有帮助!

最新更新