我正在尝试使用YouTube API for .NET从视频条目中获取评论Feed。我正在研究WPF和C#中的一个程序,但在我的生活中似乎无法弄清楚如何检索这个feed。
我尝试查看YouTube API Developer's Guide,但似乎缺少有关评论供稿的一些信息(靠近页面底部)。
答案 0 :(得分:1)
This has changed in version 3 of the YouTube API. There is a new endpoint called commentThreads/list
which allows you to return a thread of comments for a resource.
If you want to return a list of comments on a video resource, set up a GET request with vendor class
and part=id,snippet
. I'll be using https://www.youtube.com/watch?v=HwNIDcwfRLY as an example:
videoId=[VIDEO_ID]
Let's use the first comment returned as an example:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&videoId=HwNIDcwfRLY&key={YOUR_API_KEY}
Note that the comment isn't actually in this {
"kind": "youtube#commentThread",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/jhK_kJqnNF8_fiRI_o7w6ehubv8\"",
"id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04",
"snippet": {
"videoId": "HwNIDcwfRLY",
"topLevelComment": {
"kind": "youtube#comment",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/h903NemnXx-8Hfe6lRIYCFERSe4\"",
"id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04",
"snippet": {
"authorDisplayName": "mach-a-chine seahawksgoonie",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w",
"authorChannelId": {
"value": "UCBmJ0sw7plIZHLvhfz7oo_w"
},
"videoId": "HwNIDcwfRLY",
"textDisplay": "",
"authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837",
"canRate": true,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2016-02-05T03:42:35.158Z",
"updatedAt": "2016-02-05T03:42:35.158Z"
}
},
"canReply": true,
"totalReplyCount": 0,
"isPublic": true
}
}
object. topLevelComment
returns the empty string, which is a known issue with the YouTube API. We need to make an additional request to textDisplay
with commentThreads/list
, where id=[COMMENT_ID]
is [COMMENT_ID]
:
topLevelComment.id
The resulting response's HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&id=z120sfshyxzewt1nx23sevyr1vu1jd2pr04&key={YOUR_API_KEY}
dictionary will have the user's comment as the value for the snippet
key:
textDisplay
The comment is: "my next ring tone! yeah boy!"
Note that you can also pass in a list of up to 50 comma-separated "snippet": {
"authorDisplayName": "mach-a-chine seahawksgoonie",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w",
"authorChannelId": {
"value": "UCBmJ0sw7plIZHLvhfz7oo_w"
},
"videoId": "HwNIDcwfRLY",
"textDisplay": "my next ring tone! yeah boy!\ufeff",
"authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837",
"canRate": true,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2016-02-05T03:42:35.158Z",
"updatedAt": "2016-02-05T03:42:35.158Z"
}
}
or id
strings of comment objects to retrieve per API call.
See the Retrieve comments for a video guide for additional information and sample code.
答案 1 :(得分:-1)
YouTubeRequest request = ... // Your request object
Video v = ... // Your video object
Feed<Comment> comments = request.GetComments(v);
comments.entries
将包含视频v的所有评论作为Comment
个对象,因此您根本不需要使用Feed。