# TikTok Comments Scraper 💬 (`shahidirfan/tiktok-comments-scraper`) Actor

Scrape TikTok comments from videos to analyze audience reactions, spot trends, and track engagement. Collect comment text, usernames, likes, reply counts, and timestamps, then review the data in an Apify dataset. Useful for creators, marketers, and social media researchers.

- **URL**: https://apify.com/shahidirfan/tiktok-comments-scraper.md
- **Developed by:** [Shahid Irfan](https://apify.com/shahidirfan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

### What does TikTok Comments Scraper do?

TikTok Comments Scraper collects the comments under TikTok videos. Paste one or more direct video URLs, choose how many comments you want from each video, and the Actor saves one dataset row per top-level comment: author, comment text, likes, reply count, and posting time.

### Why use TikTok Comments Scraper?

- **Many videos, one run** - Paste a list of video links instead of opening each video by hand.
- **Structured output** - Every comment becomes one row with the same field names, ready for CSV, Excel, or the Apify API.
- **Top-level comments only** - Replies are not expanded, so a run stays fast and predictable.
- **Repeatable** - Schedule runs or call the Actor through the Apify API.

### How it works

The Actor reads comments from the public comment endpoint used by TikTok download services (`tikwm.com/api/comment/list`). It requests comments page by page until `maxComments` is reached, so a run takes a couple of seconds per video.

If that endpoint refuses the run's IP address, the Actor falls back to opening the video page in a stealth browser and reading the rendered comment panel. The fallback is slower, and TikTok may hide the panel from logged-out visitors, in which case the video is logged as empty.

The free endpoint throttles bursts, so the Actor spaces requests about seven seconds apart and waits 30 seconds before retrying a blocked response. A 100-comment video takes roughly 35 seconds because of this pacing.

### Input

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `videoUrls` | Array of strings | Yes | One `@tiktok` video | Direct TikTok video URLs, e.g. `https://www.tiktok.com/@user/video/1234567890` |
| `maxComments` | Integer | No | `50` | Maximum top-level comments per video |
| `proxyConfiguration` | Object | No | no proxy | Apify Proxy or custom proxy URLs |

Short links such as `https://vt.tiktok.com/...` are rejected because the video id cannot be read from them. Open the short link in a browser and use the full `tiktok.com/@user/video/...` URL.

The comment endpoint blocks some networks. If a run returns no comments, retry with an Apify Proxy enabled so the request leaves from a different IP.

### Output

| Field | Type | Description |
|-------|------|-------------|
| `video_id` | String | Numeric TikTok video id |
| `video_url` | String | Video URL that was scraped |
| `comment_id` | String | Numeric comment id, when the comment endpoint provides it |
| `comment_rank` | Number | Position of the comment in the list, starting at 1 |
| `username` | String | Comment author's username, without `@` |
| `nickname` | String | Comment author's display name |
| `text` | String | Comment text |
| `likes` | Number | Likes on the comment at collection time |
| `replies` | Number | Replies shown under the comment |
| `posted_at` | String | ISO 8601 posting time, when available |
| `time_posted` | String | Relative posting label from the browser fallback, e.g. `2d ago` |
| `collected_at` | String | ISO timestamp for when the row was saved |

Comments are saved in the order TikTok returns them, up to `maxComments` per video. Fields that a source cannot provide are `null`.

### Usage examples

#### One video, 100 comments

```json
{
  "videoUrls": ["https://www.tiktok.com/@example_creator/video/7311111111111111111"],
  "maxComments": 100
}
```

#### Several videos with a proxy

```json
{
  "videoUrls": [
    "https://www.tiktok.com/@example_creator/video/7311111111111111111",
    "https://www.tiktok.com/@another_creator/video/7322222222222222222"
  ],
  "maxComments": 50,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

### Run locally

```bash
pip install -r requirements.txt
apify run
python -m unittest discover -s tests
```

### Notes and limits

- Only public videos can be read. Private or removed videos are logged and skipped.
- Replies under a comment are counted (`replies`) but not saved as separate rows.
- The comment endpoint is a third-party service. If it changes or goes offline, the browser fallback takes over.
- The browser fallback parses the current TikTok web markup. If TikTok changes its page structure, comment text or like counts can come back empty until the selectors are updated.

# Actor input Schema

## `videoUrls` (type: `array`):

Direct links to the videos you want comments from, for example https://www.tiktok.com/@user/video/1234567890. Every video is scraped in the same run.

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

Maximum number of top-level comments to collect from each video. The Actor stops earlier when the comment list runs out.

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

Choose to use no proxy, Apify Proxy, or provide custom proxy URLs. No proxy is used by default.

## Actor input object example

```json
{
  "videoUrls": [
    "https://www.tiktok.com/@tiktok/video/7704834703446117662"
  ],
  "maxComments": 50,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

# 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 = {
    "videoUrls": [
        "https://www.tiktok.com/@tiktok/video/7704834703446117662"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("shahidirfan/tiktok-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 = { "videoUrls": ["https://www.tiktok.com/@tiktok/video/7704834703446117662"] }

# Run the Actor and wait for it to finish
run = client.actor("shahidirfan/tiktok-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 '{
  "videoUrls": [
    "https://www.tiktok.com/@tiktok/video/7704834703446117662"
  ]
}' |
apify call shahidirfan/tiktok-comments-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,shahidirfan/tiktok-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/vnCXfemT3o1sYgekB/builds/l4cdCb8tP66Frl31s/openapi.json
