Chr*_*isc 6 c# youtube wpf youtube-api youtube-data-api
我正在尝试使用YouTube API for .NET从视频条目中获取评论Feed.我正在研究WPF和C#中的程序,但在我的生活中似乎无法弄清楚如何检索这个feed.
我尝试查看YouTube API开发人员指南,但似乎缺少有关评论Feed的一些信息(靠近页面底部).
这在 YouTube API 版本 3 中发生了变化。有一个名为的新端点commentThreads/list,它允许您返回资源的评论线程。
如果您想返回视频资源的评论列表,请使用part=id,snippet和设置 GET 请求videoId=[VIDEO_ID]。我将使用https://www.youtube.com/watch?v=HwNIDcwfRLY作为示例:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&videoId=HwNIDcwfRLY&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
我们以返回的第一条评论为例:
{
"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
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,注释实际上并不在此topLevelComment对象中。 textDisplay返回空字符串,这是YouTube API 的一个已知问题。我们需要向commentThreads/listwith提出额外的请求id=[COMMENT_ID],其中[COMMENT_ID]是topLevelComment.id:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&id=z120sfshyxzewt1nx23sevyr1vu1jd2pr04&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
生成的响应的snippet字典将把用户的评论作为textDisplay键的值:
"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"
}
}
Run Code Online (Sandbox Code Playgroud)
评论是:“我的下一个铃声!是的,男孩!”
请注意,您还可以传入最多 50 个逗号分隔的列表id或videoId注释对象字符串以检索每个 API 调用。
有关其他信息和示例代码,请参阅检索视频指南的注释。
| 归档时间: |
|
| 查看次数: |
4050 次 |
| 最近记录: |