I am attempting to get the Comments Feed from a video entry using the YouTube API for .NET. I am working on a program in WPF and C#, but can't seem for the life of me to figure out how to retrieve this feed.
I tried looking at the YouTube API Developer's Guide, but it seems to be missing some information about Comment Feeds (near the bottom of the page).
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 part=id,snippet
and videoId=[VIDEO_ID]
. I'll be using https://www.youtube.com/watch?v=HwNIDcwfRLY as an example:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&videoId=HwNIDcwfRLY&key={YOUR_API_KEY}
Let's use the first comment returned as an example:
{
"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
}
}
Note that the comment isn't actually in this topLevelComment
object. textDisplay
returns the empty string, which is a known issue with the YouTube API. We need to make an additional request to commentThreads/list
with id=[COMMENT_ID]
, where [COMMENT_ID]
is topLevelComment.id
:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&id=z120sfshyxzewt1nx23sevyr1vu1jd2pr04&key={YOUR_API_KEY}
The resulting response's snippet
dictionary will have the user's comment as the value for the textDisplay
key:
"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"
}
}
The comment is: "my next ring tone! yeah boy!"
Note that you can also pass in a list of up to 50 comma-separated id
or videoId
strings of comment objects to retrieve per API call.
See the Retrieve comments for a video guide for additional information and sample code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With