YouTube API如何获得评论和喜欢的回复 [英] Youtube api how get replies to comments and likes
问题描述
要使用此注释来获取
评论主题:列表
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."
}
}
但是如何获得每个评论的回复,并像是否知道?
But how get each comment replies, and check user like it or not, any knows?
推荐答案
您可以使用 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
。
Regarding likes, you may want to check out the 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 islike
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.
此属性的有效值为:
- like
- none
然后检查 snippet.likeCount
以获得评论已收到的点赞总数(正面评分)。
Then check the snippet.likeCount
to get the total number of likes (positive ratings) the comment has received.
这是示例JSON结构,它显示了评论
资源。
{
"kind": "youtube#comment",
"etag": etag,
"id": string,
"snippet": {
......
"authorChannelId": {
"value": string
},
......
"viewerRating": string,
"likeCount": unsigned integer,
......
}
}
希望这会有所帮助!
这篇关于YouTube API如何获得评论和喜欢的回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!