# YouTube Comments Scraper (`adaptable_wheelhouse/youtube-comments-scraper`) Actor

Scrape YouTube comments and replies from any number of videos: text, author, likes, reply count, creator hearts and channel-owner replies. Sort by top or newest, filter by date. No API key or quota.

- **URL**: https://apify.com/adaptable_wheelhouse/youtube-comments-scraper.md
- **Developed by:** [Mr T](https://apify.com/adaptable_wheelhouse) (community)
- **Categories:** Social media, Videos
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.20 / 1,000 comments

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### YouTube Comments Scraper

Download comments and replies from any number of YouTube videos, with the details the YouTube Data API leaves out: whether the creator **hearted** a comment and whether the **channel owner** wrote it. No API key, no quota, no Google account.

**You only pay per comment returned.** Videos that are unavailable or have no comments still appear in the results so you know what happened, but they are free.

#### What you get for each comment

- Comment text, ID and approximate posting time
- Author handle, channel ID and verified badge
- Likes and number of replies
- **Creator heart**, and whether the **video's own channel** wrote it
- For replies: the ID of the comment they answer
- Video ID, title, URL and the video's total comment count

#### How to use it

1. Add one or more video URLs to **Video URLs**. You can also upload a CSV or link a Google Sheet. Watch links, `youtu.be`, Shorts and live links all work.
2. Set **Max comments per video**.
3. Optionally choose **Newest first**, set **Max replies per comment** to include replies, or set **Oldest comment date** to keep only recent comments.
4. Click **Start**, then download the results as JSON, CSV, Excel or HTML.

##### Example input

```json
{
    "startUrls": [{ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }],
    "maxComments": 300,
    "sortCommentsBy": "NEWEST_FIRST",
    "maxRepliesPerComment": 10,
    "oldestCommentDate": "7 days"
}
```

#### Example output

```json
{
    "comment": "I Rick rolled my entire French class because we had to study a city in France…",
    "cid": "UgzKYksqeQ5gA3t0g0F4AaABAg",
    "author": "@grustache4569",
    "authorChannelId": "UCKrzgYonJnMd0Dk7zQXjYXw",
    "authorIsChannelOwner": false,
    "authorIsVerified": false,
    "videoId": "dQw4w9WgXcQ",
    "pageUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "title": "Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)",
    "commentsCount": 2400000,
    "replyCount": 636,
    "voteCount": 105000,
    "hasCreatorHeart": false,
    "type": "comment",
    "replyToCid": null,
    "publishedTimeText": "6 years ago (edited)",
    "approxPublishedAt": "2020-10-26T18:40:00.000Z"
}
```

Replies have `"type": "reply"` and `replyToCid` set to their parent's `cid`, and they come right after their parent.

When a video can't be scraped, you get one item like this instead (not charged):

```json
{
    "url": "https://www.youtube.com/watch?v=xxxxxxxxxxx",
    "input": "https://youtu.be/xxxxxxxxxxx",
    "error": "VIDEO_UNAVAILABLE",
    "note": "This video is not available"
}
```

| `error` | Meaning |
|---|---|
| `VIDEO_UNAVAILABLE` | The video doesn't exist, was removed or is private. |
| `NO_COMMENTS` | Comments are turned off, the video has none, or none match the date filter. |
| `INVALID_INPUT` | The URL isn't a YouTube video URL. |
| `BLOCKED`, `RATE_LIMITED`, `TIMEOUT`, `NETWORK_ERROR`, `SERVER_ERROR`, `HTTP_ERROR`, `UNEXPECTED_RESPONSE` | YouTube refused or failed on every retry. Running again usually works. |

#### Good to know

- **Dates are approximate.** YouTube shows only relative ages ("3 weeks ago"). `approxPublishedAt` is computed from that, so "1 year ago" can be off by months. The date filter uses the same approximation.
- **Likes and the total comment count are as displayed.** Above 1,000 they are rounded (105K becomes 105000).
- **Replies count toward the limit.** With 100 max comments and 10 replies per comment, you get roughly 9 comments and their replies.

#### Proxies

YouTube blocks most cloud IP addresses, so the default proxy is Apify **Residential**. A page of 20 comments uses roughly 30–40 KB of proxy traffic.

#### Using it from code

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('adaptable_wheelhouse/youtube-comments-scraper').call({
    startUrls: [{ url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' }],
    maxComments: 500,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

#### Is it legal to scrape YouTube comments?

This actor reads only public comments that anyone can see on youtube.com without logging in. Comments contain personal data (usernames and what people wrote), which is protected by laws such as GDPR. Only collect it if you have a legitimate reason, and check with a lawyer if you are unsure.

# Actor input Schema

## `startUrls` (type: `array`):

YouTube video URLs (watch, youtu.be, shorts, live or embed links). You can also upload a CSV or link a Google Sheet.

## `maxComments` (type: `integer`):

Maximum number of rows per video, counting both comments and replies.

## `sortCommentsBy` (type: `string`):

YouTube's comment order.

## `maxRepliesPerComment` (type: `integer`):

Also fetch up to this many replies under each comment. Replies come right after their comment and count toward 'Max comments per video'. 0 = no replies.

## `oldestCommentDate` (type: `string`):

Only comments posted on or after this date (YYYY-MM-DD), or within an age such as '1 day' (today only), '7 days', '2 weeks', '1 month'. Switches the order to newest first. YouTube only shows relative ages ('3 weeks ago'), so the cut-off is approximate.

## `maxConcurrency` (type: `integer`):

How many videos to scrape at the same time.

## `proxyConfiguration` (type: `object`):

YouTube blocks most datacenter IPs. Residential proxies are strongly recommended.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    }
  ],
  "maxComments": 100,
  "sortCommentsBy": "TOP_COMMENTS",
  "maxRepliesPerComment": 0,
  "maxConcurrency": 3,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `comments` (type: `string`):

All scraped comments and replies.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        {
            "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
        }
    ],
    "maxComments": 100,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("adaptable_wheelhouse/youtube-comments-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "startUrls": [{ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }],
    "maxComments": 100,
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("adaptable_wheelhouse/youtube-comments-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    }
  ],
  "maxComments": 100,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call adaptable_wheelhouse/youtube-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,adaptable_wheelhouse/youtube-comments-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/4fuSiR1U5DOpi2XWU/builds/eyu0kcLN4lUoOTEv1/openapi.json
