gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:14:51 31 4
gpt4 key购买 nike

使用此获取评论

评论主题:列表

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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com