YouTube

YouTube API v2.0 – Comments

Note: The YouTube Data API (v2) has been officially deprecated as of March 4, 2014. Please refer to our deprecation policy for more information.

IMPORTANT: YouTube is switching to a new commenting system that may require you to modify API calls related to comments. Please review the upcoming changes to comments for a complete explanation of the changes.

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:

  1. Retrieving comments for a video
  2. Adding a comment in response to a video
  3. Adding a comment in reply to another comment
  4. 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/&quot;DE8HQXo-eip7ImA9WxRQGU4.&quot;'>
  <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/&quot;D0YASX47eCp7ImA9WxRQGU8.&quot;'>
    <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

Note: As part of YouTube's move to a new commenting system, this API feature has been deprecated and is no longer supported. Comments that were replies to other comments now appear as regular comments in API responses.

The new commenting system, which is powered by Google+, supports threading for comments made through that system. With the new system, comment replies are retrieved using the Google+ API's comments:list method. See the article that explains changes to comments in the API for more details.

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

Note: As part of YouTube's move to a new commenting system, this API feature has been deprecated and is no longer supported.

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.

pagination links

« Previous
Adding a Rating
Next »
Complaints

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.