A comment is a text response to a video. Logged-in users can add comments to a video but cannot modify or delete those comments. In addition, please note that YouTube will convert any HTML markup that appears in a comment into plain text. Typically, a user would add a comment to a video after watching that video.
This page contains the following sections:
- Retrieving comments for a video
- Adding a comment in response to a video
- Adding a comment in reply to another comment
- Deleting a comment
Retrieving comments for a video
Each video entry contains a <gd:comments> tag, which encapsulates the URL to which you will send API requests to retrieve or append to the list of comments for the video. The sample XML below shows how this URL appears in an API response:
<feed>
<entry>
...
<media:group>
...
</media:group>
<gd:comments>
<gd:feedLink
href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments'/>
</gd:comments>
</entry>
</feed>
Each comment has an author, a title and content. The following XML shows a sample API response containing a comments feed:
<?xml version='1.0' encoding='UTF-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"DE8HQXo-eip7ImA9WxRQGU4."'> <id>tag:youtube,2008:video:ZTUVgYoeN_b:comments</id> <updated>2008-07-18T22:10:57.065Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#comment'/> <title>Comments on 'My Walk with Mr. Darcy'</title> <logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo> <link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b?v=2'/> <link rel='alternate' type='text/html' href='https://www.youtube.com/watch?v=ZTUVgYoeN_b'/> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments?v=2'/> <link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments?v=2'/> <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments/batch?v=2'/> <link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments?...'/> <link rel='service' type='application/atomsvc+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments?alt=atom-service&v=2'/> <link rel='next' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments?...'/> <author> <name>YouTube</name> <uri>http://www.youtube.com/</uri> </author> <generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator> <openSearch:totalResults>9051</openSearch:totalResults> <openSearch:startIndex>1</openSearch:startIndex> <openSearch:itemsPerPage>25</openSearch:itemsPerPage> <entry gd:etag='W/"D0YASX47eCp7ImA9WxRQGU8."'> <id>tag:youtube,2008:video:xpI6VNvRTII:comment:F53EAC190E4EA5C9</id> <published>2008-07-18T14:57:59.000-07:00</published> <updated>2008-07-18T14:57:59.000-07:00</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#comment'/> <title>Walking is fun</title> <content>I like it a lot.</content> <link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b?v=2'/> <link rel='alternate' type='text/html' href='https://www.youtube.com/watch?v=ZTUVgYoeN_b'/> <link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/ZTUVgYoeN_b/comments/F53EAC190E4EA5C9?v=2'/> <author> <name>GoogleDevelopers</name> <uri>https://gdata.youtube.com/feeds/api/users/GoogleDevelopers</uri> </author> </entry> <entry> ... </entry> ... </feed>
Identifying comments that are replies to other comments
YouTube users may respond to a comment with another comment. When displaying these comments, you may want to indent comments that reply to other comments to identify comment threads. You could also link comments that reply to other comments to help users to follow a comment thread. In an XML response, a comment that was posted in response to another comment will contain an in-reply-to link as shown in the following <link> tag:
<link rel="http://gdata.youtube.com/schemas/2007#in-reply-to" type="application/atom+xml" href="https://gdata.youtube.com/feeds/api/videos/2cd.../comments/978..."/>
Adding a comment in response to a video
To add a comment to a video, send a POST request to the URL identified in the <gd:feedLink> tag that appears inside the <gd:comments> tag. The actual comment that you are submitting appears as the value of the <content> tag in the XML that constitutes the body of the POST request.
The sample XML API request below demonstrates how to add a comment to a video.
POST /feeds/api/videos/VIDEO_ID/comments HTTP/1.1 Host: gdata.youtube.com Content-Type: application/atom+xml Content-Length: CONTENT_LENGTH Authorization: Bearer ACCESS_TOKEN GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY <?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <content>This is a crazy video.</content> </entry>
Adding a comment in reply to another comment
The API request for adding a comment in response to a video is nearly identical to the API request for adding a comment in reply to another comment. The only difference is that the latter request contains an additional <link> tag that identifies the comment being replied to. The following instructions explain how to format the <link> tag:
- Set the
relattribute value tohttp://gdata.youtube.com/schemas/2007#in-reply-to. - Set the
typeattribute value toapplication/atom+xml. - Set the
hrefattribute value to the self link for the comment being replied to.
The sample XML API request below demonstrates how to add a comment in reply to another comment. The <link> tag that indicates that the comment is a reply to another comment is highlighted in bold text.
POST /feeds/api/videos/VIDEO_ID/comments HTTP/1.1 Host: gdata.youtube.com Content-Type: application/atom+xml Content-Length: CONTENT_LENGTH Authorization: Bearer ACCESS_TOKEN GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY <?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <link rel="http://gdata.youtube.com/schemas/2007#in-reply-to" type="application/atom+xml" href="https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments/COMMENT_ID"/> <content>This is a comment about another comment.</content> </entry>
Note: The POST URL for this API request specifies the video associated with the new comment. The <link> tag identifies the original comment to which the new comment replies. The new comment and the original comment must be associated with the same video.
Deleting a comment
You can delete a comment by sending a DELETE request to the comment's edit URL. The following sample API request demonstrates how to delete a comment:
Host: gdata.youtube.com Content-Type: application/atom+xml Authorization: Bearer ACCESS_TOKEN GData-Version: 2 X-GData-Key: key=DEVELOPER_KEY
An API request to delete a comment must be authenticated by either the comment's author or the owner of the video associated with the comment. If the request is not properly authenticated, the API will return a 401 (Unauthorized) or 403 (Forbidden) HTTP response code.
|
« Previous Adding a Rating |
Next » Video Responses |