We are updating the Data API to match how YouTube counts views for Shorts.
Learn more
Implementation: Comments
Stay organized with collections
Save and categorize content based on your preferences.
The following examples show how to use the YouTube Data API (v3) to perform functions related to comments.
To retrieve a list of comment threads for a video, call the commentThreads.list
method. Set the following parameter values in your request:
-
part
: Set the parameter value to snippet
if you only want to retrieve top-level comments or to snippet,replies
if you also want to retrieve replies to top-level comments. (Note that a commentThread
resource does not necessarily contain all replies to a comment, and you need to use the comments.list
method if you want to retrieve all replies for a particular comment.)
-
videoId
: Specify the YouTube video ID of the video for which you are retrieving comments.
The request below retrieves comments and comment replies related to the video of the keynote speech at the 2014 Google I/O conference, which has the video ID wtLJPvx7-ys
.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.commentThreads.list?
part=snippet,replies
&videoId=wtLJPvx7-ys
To update the text of a top-level comment or a reply to a top-level comment, call the comments.update
method. Set the part
parameter's value to snippet
. In the request body, the id
property identifies the comment that you are modifying and the new comment text.
- In a
commentThread
resource, which identifies a top-level comment, the snippet.topLevelComment[].id
property specifies the comment's unique ID.
- In a
comment
resource, which can identify either a top-level comment or a reply to a comment, the id
property specifies the comment's unique ID.
The sample request below updates the text of an existing comment.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.comments.update?
part=snippet
The request body contains the JSON snippet shown below. To execute the request in the APIs Explorer, set the id
property's value to identify the comment that you are updating. The request must be authorized by the comment's author.
{
"id": "COMMENT_ID",
"snippet": {
"textOriginal": "That is true."
}
}
To set a comment's moderation status, call the comments.setModerationStatus
method. This action is used when a channel owner moderates comments on the channel or the channel's videos.
When calling this method, set the id
parameter's value to identify the comment. Also set the moderationStatus
parameter to the desired status. A comment's status can only be adjusted by the owner of the channel where the comment appears.
-
Step 1: Retrieve comments that are being held for review
Call the commentThreads.list
method to retrieve comments for the channel or video. Set the moderationStatus
parameter's value to heldForReview
. The API response could be used to display a list of comments with an option for the channel owner to publish or reject each one.
-
Step 2: Update the moderation status of a comment
Call the comments.setModerationStatus
method to update the comment's status. Use the id
parameter's value to specify the comment's unique ID. Set the moderationStatus
parameter to either published
or rejected
. If you are rejecting a comment, you can also set the banAuthor
parameter to true
to prevent the author from making additional comments on the channel or video.
Note: The API does not provide a way to list or otherwise discover rejected comments. However, you can still change the moderation status of a rejected comment to published
if the comment's unique ID is known. In addition, once a comment's moderation status is updated to either published
or rejected
, the moderation status cannot be changed back to heldForReview
.
This example shows how to delete a comment. The example has the following steps:
-
Step 1: Retrieve the comment ID
Follow the steps above to retrieve a list of comments for a video or channel. Remember that a comment can only be deleted by its author, so you will need to compare the value of a comment
resource's snippet.authorChannelId.value
property to the authenticated user's channel ID to determine whether the user can delete that particular comment.
-
Step 2: Delete the comment or comment thread
Once you have identified the ID of the comment thread or comment that you are deleting, call the comments.delete
method to delete that comment. Use the id
parameter value to identify the comment ID or comment thread ID that you are deleting. The request must be authorized using OAuth 2.0. If you are testing this query in the APIs Explorer, you will need to substitute a valid comment ID or comment thread ID for the id
parameter value in the request below.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.comments.delete?
id=COMMENT_ID
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThe \u003ccode\u003ecomments.markAsSpam\u003c/code\u003e method is no longer supported in the YouTube Data API (v3).\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve comments for a specific video using the \u003ccode\u003ecommentThreads.list\u003c/code\u003e method by setting the \u003ccode\u003evideoId\u003c/code\u003e parameter, and you can choose to include replies to comments by setting the \u003ccode\u003epart\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve comments about or associated with a specific channel by using the \u003ccode\u003ecommentThreads.list\u003c/code\u003e method and setting either the \u003ccode\u003echannelId\u003c/code\u003e or \u003ccode\u003eallThreadsRelatedToChannelId\u003c/code\u003e parameters, respectively, instead of the \u003ccode\u003evideoId\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eNew comments can be added to either a video or a channel using the \u003ccode\u003ecommentThreads.insert\u003c/code\u003e method, while replies to comments are added via the \u003ccode\u003ecomments.insert\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eTo update the text or moderate a comment, you can use the \u003ccode\u003ecomments.update\u003c/code\u003e method to modify the text, and \u003ccode\u003ecomments.setModerationStatus\u003c/code\u003e to change a comment's moderation status.\u003c/p\u003e\n"]]],["The YouTube Data API v3 allows managing comments via several methods. `commentThreads.list` retrieves comments for a video or channel, using `videoId`, `channelId`, or `allThreadsRelatedToChannelId`. `commentThreads.insert` adds a top-level comment, requiring `snippet.textOriginal`. `comments.insert` adds a reply, referencing the parent comment's ID. `comments.update` modifies comment text. `comments.setModerationStatus` sets a comment's status to `published` or `rejected`, and `comments.delete` removes comments. The `comments.markAsSpam` is no longer supported.\n"],null,["The [comments.markAsSpam](/youtube/v3/docs/comments/markAsSpam) method is no longer supported.\n\nThe following examples show how to use the YouTube Data API (v3) to perform functions related to comments.\n\nRetrieve comments for a video \nTo retrieve a list of comment threads for a video, call the [commentThreads.list](/youtube/v3/docs/commentThreads/list) method. Set the following parameter values in your request:\n\n- [part](/youtube/v3/docs/commentThreads/list#part): Set the parameter value to `snippet` if you only want to retrieve top-level comments or to `snippet,replies` if you also want to retrieve replies to top-level comments. (Note that a `commentThread` resource does not necessarily contain all replies to a comment, and you need to use the [comments.list](/youtube/v3/docs/comments/list) method if you want to retrieve all replies for a particular comment.)\n\n- [videoId](/youtube/v3/docs/commentThreads/list#videoId): Specify the YouTube video ID of the video for which you are retrieving comments.\n\nThe request below retrieves comments and comment replies related to the video of the keynote speech at the 2014 Google I/O conference, which has the video ID `wtLJPvx7-ys`. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.commentThreads.list?\npart=snippet,replies\n&videoId=wtLJPvx7-ys\n```\n\nRetrieve comments about or associated with a channel \nThe API supports the ability to either retrieve comments threads about a channel or to retrieve all comment threads associated with a channel. In the latter case, the API could contain comments about the channel or about any of the channel's videos.\n\n\u003cbr /\u003e\n\n- To retrieve comments about a channel, follow the instructions for [retrieving comments for a video](#comments). However, instead of setting the `videoId` parameter, set the [channelId](/youtube/v3/docs/commentThreads/list#channelId) parameter to identify the channel.\n\n \u003cbr /\u003e\n\n- To retrieve comments associated with a channel, follow the instructions for [retrieving comments for a video](#comments). However, instead of setting the `videoId` parameter, set the [allThreadsRelatedToChannelId](/youtube/v3/docs/commentThreads/list#allThreadsRelatedToChannelId) parameter to identify the channel.\n\n \u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThe request below retrieves all comment threads associated with the **GoogleDevelopers** YouTube channel: \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.commentThreads.list?\npart=snippet,replies\n&allThreadsRelatedToChannelId=UC_x5XG1OV2P6uZZ5FSM9Ttw\n```\n\nAdding a comment \nCall the [commentThreads.insert](/youtube/v3/docs/commentThreads/insert) method to add a new, top-level comment to a channel or a video. Set the request's [part](/youtube/v3/docs/commentThreads/insert#part) parameter value to `snippet`. The body of the request is a [commentThread resource](/youtube/v3/docs/commentThreads#resource) in which the [snippet.topLevelComment[].snippet[].textOriginal](/youtube/v3/docs/commentThreads#snippet.topLevelComment) property contains the comment text. This request must be authorized using OAuth 2.0.\n\n- To add a comment to a channel, use the [snippet.channelId](/youtube/v3/docs/commentThreads#snippet.channelId) property to identify the channel.\n- To add a comment to a video, use the [snippet.channelId](/youtube/v3/docs/commentThreads#snippet.channelId) property to identify the channel that uploaded the video. Also use the [snippet.videoId](/youtube/v3/docs/commentThreads#snippet.videoId) property to identify the video.\n\nThe following sample request adds a comment to a video. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.commentThreads.insert?\npart=snippet\n```\n\nThe request inserts the resource shown below. \n\n```\n{\n \"snippet\": {\n \"channelId\": \"UC_x5XG1OV2P6uZZ5FSM9Ttw\",\n \"topLevelComment\": {\n \"snippet\": {\n \"textOriginal\": \"This video is awesome!\"\n }\n },\n \"videoId\": \"MILSirUni5E\"\n }\n}\n```\n\nReply to a comment \nCall the [comments.insert](/youtube/v3/docs/comments/insert) method to reply to a comment. Set the request's [part](/youtube/v3/docs/comments/insert#part) parameter value to `snippet`. The body of the request is a [comment resource](/youtube/v3/docs/comments#resource) in which the [snippet.textOriginal](/youtube/v3/docs/comments#snippet.textOriginal) property contains the comment text. The [snippet.parentId](/youtube/v3/docs/comments#snippet.parentId) property identifies the comment associated with the reply, and it's value is a [commentThread resource's ID](/youtube/v3/docs/commentThreads#id). This request must be authorized using OAuth 2.0.\n\nThe following sample request adds a reply to an existing comment. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.comments.insert?\npart=snippet\n```\n\nThe request inserts the resource shown below. To execute the request in the APIs Explorer, use the `snippet.parentId` property's value to identify the top-level comment associated with the reply. In a `commentThread` resource, the [snippet.topLevelComment[].id](/youtube/v3/docs/commentThreads#snippet.topLevelComment) property specifies the resource's unique ID. \n\n```\n{\n \"snippet\": {\n \"parentId\": \"COMMENT_THREAD_ID\",\n \"textOriginal\": \"That is true.\"\n }\n}\n```\n\nUpdate a top-level comment or comment reply \nTo update the text of a top-level comment or a reply to a top-level comment, call the [comments.update](/youtube/v3/docs/comments/update) method. Set the `part` parameter's value to `snippet`. In the request body, the `id` property identifies the comment that you are modifying and the new comment text.\n\n\u003cbr /\u003e\n\n- In a `commentThread` resource, which identifies a top-level comment, the [snippet.topLevelComment[].id](/youtube/v3/docs/commentThreads#snippet.topLevelComment) property specifies the comment's unique ID.\n- In a `comment` resource, which can identify either a top-level comment or a reply to a comment, the [id](/youtube/v3/docs/comments#id) property specifies the comment's unique ID.\n\n\u003cbr /\u003e\n\nThe sample request below updates the text of an existing comment. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.comments.update?\npart=snippet\n```\n\nThe request body contains the JSON snippet shown below. To execute the request in the APIs Explorer, set the `id` property's value to identify the comment that you are updating. The request must be authorized by the comment's author. \n\n```\n{\n \"id\": \"COMMENT_ID\",\n \"snippet\": {\n \"textOriginal\": \"That is true.\"\n }\n}\n```\n\nSet a comment's moderation status \nTo set a comment's moderation status, call the [comments.setModerationStatus](/youtube/v3/docs/comments/setModerationStatus) method. This action is used when a channel owner moderates comments on the channel or the channel's videos.\n\nWhen calling this method, set the `id` parameter's value to identify the comment. Also set the `moderationStatus` parameter to the desired status. A comment's status can only be adjusted by the owner of the channel where the comment appears.\n\n- **Step 1: Retrieve comments that are being held for review**\n\n Call the [commentThreads.list](/youtube/v3/docs/commentThreads/list) method to retrieve comments for the channel or video. Set the [moderationStatus](/youtube/v3/docs/commentThreads/list#moderationStatus) parameter's value to `heldForReview`. The API response could be used to display a list of comments with an option for the channel owner to publish or reject each one.\n- **Step 2: Update the moderation status of a comment**\n\n Call the [comments.setModerationStatus](/youtube/v3/docs/comments/setModerationStatus) method to update the comment's status. Use the [id](/youtube/v3/docs/comments/setModerationStatus#id) parameter's value to specify the comment's unique ID. Set the [moderationStatus](/youtube/v3/docs/comments/setModerationStatus#moderationStatus) parameter to either `published` or `rejected`. If you are rejecting a comment, you can also set the [banAuthor](/youtube/v3/docs/comments/setModerationStatus#banAuthor) parameter to `true` to prevent the author from making additional comments on the channel or video.\n\n**Note:** The API does not provide a way to list or otherwise discover rejected comments. However, you can still change the moderation status of a rejected comment to `published` if the comment's unique ID is known. In addition, once a comment's moderation status is updated to either `published` or `rejected`, the moderation status cannot be changed back to `heldForReview`.\n\nRemove a comment \nThis example shows how to delete a comment. The example has the following steps:\n\n- **Step 1: Retrieve the comment ID**\n\n Follow the steps above to [retrieve a list of comments](#comments) for a video or channel. Remember that a comment can only be deleted by its author, so you will need to compare the value of a `comment` resource's [snippet.authorChannelId.value](/youtube/v3/docs/comments#snippet.authorChannelId.value) property to the authenticated user's channel ID to determine whether the user can delete that particular comment.\n- **Step 2: Delete the comment or comment thread**\n\n Once you have identified the ID of the comment thread or comment that you are deleting, call the [comments.delete](/youtube/v3/docs/comments/delete) method to delete that comment. Use the [id](/youtube/v3/docs/comments/delete#id) parameter value to identify the comment ID or comment thread ID that you are deleting. The request must be authorized using OAuth 2.0. If you are testing this query in the APIs Explorer, you will need to substitute a valid comment ID or comment thread ID for the `id` parameter value in the request below. \n\n ```\n https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.comments.delete?\n id=COMMENT_ID\n ```"]]