# TikTok Video Engagement Scraper (`dwi_wahyu/tiktok-video-engagement-scraper`) Actor

Collects engagement metrics and metadata (views, likes, comments, shares, saves, favorites, duration, postedAt, description, and author details) for TikTok videos.

- **URL**: https://apify.com/dwi_wahyu/tiktok-video-engagement-scraper.md
- **Developed by:** [Dwi Wahyu](https://apify.com/dwi_wahyu) (community)
- **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

## TikTok Video Engagement Scraper

An Apify Actor built in TypeScript with the Apify SDK and Crawlee that collects engagement metrics and video metadata for a batch of TikTok video URLs.

### Features & Scope

Accepts one or more TikTok video URLs (`https://www.tiktok.com/@<user>/video/<id>` or short links `https://vm.tiktok.com/...` / `https://www.tiktok.com/t/...`) and returns for each video:

- **`videoUrl`** — Canonical normalized TikTok video URL (`https://www.tiktok.com/@<user>/video/<id>`)
- **`videoId`** — Numeric TikTok video ID
- **`authorUsername`** — Creator account username (`uniqueId` without `@`)
- **`authorNickname`** — Creator display name (`nickname`)
- **`description`** — Video caption / description text
- **`views`** — Video play / view count (`playCount`)
- **`likes`** — Video like count (`diggCount`)
- **`comments`** — Video comment count (`commentCount`)
- **`shares`** — Video share count (`shareCount`)
- **`saves`** — Video save / bookmark count (`collectCount`)
- **`favorites`** — Video favorite / bookmark count (`collectCount`)
- **`durationSeconds`** — Video duration in seconds
- **`postedAt`** — ISO 8601 timestamp when the video was published
- **`scrapedAt`** — ISO 8601 timestamp when the video was scraped
- **`error`** — Error description if the URL was invalid or the video was deleted/private/unavailable (`null` on success)

#### Strict Scope Guarantees

- **No extraneous crawling**: Scrapes only the video URLs provided in the input batch (never crawls user profiles, hashtags, or search pages).
- **No fabricated numbers**: Any metric that is not publicly available for a video is returned as `null` — values are never estimated or guessed.
- **Short link resolution & URL normalization**: Resolves `vm.tiktok.com`, `vt.tiktok.com`, and `tiktok.com/t/...` short links to their canonical URL before scraping, strips query parameters and trailing slashes, and deduplicates repeated videos in a single run.
- **Every input accounted for**: Invalid URLs or deleted/private videos do not crash the run — they produce a dataset item with a descriptive `error` field and `null` metrics.

***

### Input

The Actor input is defined in [`.actor/input_schema.json`](./.actor/input_schema.json) (and [`INPUT_SCHEMA.json`](./INPUT_SCHEMA.json)):

| Field | Type | Required | Default | Description |
| :--- | :--- | :---: | :---: | :--- |
| `videoUrls` | `string[]` | Yes | — | One or more TikTok video URLs (`https://www.tiktok.com/@<user>/video/<id>`) or short links (`https://vm.tiktok.com/...`, `https://www.tiktok.com/t/...`). |
| `proxyConfiguration` | `object` | No | `{ "useApifyProxy": true }` | Apify Proxy configuration. Use Residential proxies if plain requests are blocked by TikTok. |
| `maxConcurrency` | `integer` | No | `4` | Number of TikTok video URLs processed in parallel (`1`–`10`). |
| `sessionCookie` | `string` (secret) | No | — | Optional TikTok `sessionid` cookie value if authenticated access is needed for restricted videos. Stored encrypted and never logged. |

#### Example Input

```json
{
    "videoUrls": [
        "https://www.tiktok.com/@tiktok/video/7106594312292453675",
        "https://www.tiktok.com/@zachking/video/6768504823336815877",
        "https://www.tiktok.com/@420doggface208/video/6876424179084709126"
    ],
    "proxyConfiguration": {
        "useApifyProxy": true
    },
    "maxConcurrency": 4
}
```

***

### Output

The Actor stores one item per deduplicated TikTok video URL in the default Apify Dataset, rendered as a table in the Apify Console via [`.actor/dataset_schema.json`](./.actor/dataset_schema.json).

#### Output Schema

```json
{
    "videoUrl": "string",
    "videoId": "string | null",
    "authorUsername": "string | null",
    "authorNickname": "string | null",
    "description": "string | null",
    "views": "number | null",
    "likes": "number | null",
    "comments": "number | null",
    "shares": "number | null",
    "saves": "number | null",
    "favorites": "number | null",
    "durationSeconds": "number | null",
    "postedAt": "ISO 8601 string | null",
    "scrapedAt": "ISO 8601 string",
    "error": "string | null"
}
```

#### Example Output

```json
[
    {
        "videoUrl": "https://www.tiktok.com/@tiktok/video/7106594312292453675",
        "videoId": "7106594312292453675",
        "authorUsername": "tiktok",
        "authorNickname": "TikTok",
        "description": "how many frogs did you find? 🐸 check out tiktok’s #Minecraft community today! @Gorillo",
        "views": 591900,
        "likes": 98900,
        "comments": 1276,
        "shares": 360,
        "saves": 59206,
        "favorites": 59206,
        "durationSeconds": 24,
        "postedAt": "2022-06-07T20:15:29.000Z",
        "scrapedAt": "2026-10-19T03:32:00.000Z",
        "error": null
    },
    {
        "videoUrl": "https://www.tiktok.com/@zachking/video/6768504823336815877",
        "videoId": "6768504823336815877",
        "authorUsername": "zachking",
        "authorNickname": "Zach King",
        "description": "They rejected my application to Hogwarts, but I still found a way to be a wizard. 🧹#illusion #magic #harrypotter",
        "views": 2400000000,
        "likes": 29600000,
        "comments": 782400,
        "shares": 1100000,
        "saves": 997818,
        "favorites": 997818,
        "durationSeconds": 15,
        "postedAt": "2019-12-09T18:15:29.000Z",
        "scrapedAt": "2026-10-19T03:32:01.000Z",
        "error": null
    },
    {
        "videoUrl": "https://www.tiktok.com/@420doggface208/video/6876424179084709126",
        "videoId": "6876424179084709126",
        "authorUsername": "420doggface208",
        "authorNickname": "Doggface",
        "description": "Morning vibe #fyp #foryoupage #fleetwoodmac #cranberrydreams #doggface",
        "views": 99700000,
        "likes": 14900000,
        "comments": 128500,
        "shares": 723900,
        "saves": 646176,
        "favorites": 646176,
        "durationSeconds": 23,
        "postedAt": "2020-09-25T15:02:13.000Z",
        "scrapedAt": "2026-10-19T03:32:02.000Z",
        "error": null
    },
    {
        "videoUrl": "https://www.tiktok.com/@bellapoarch/video/6862153058223197445",
        "videoId": "6862153058223197445",
        "authorUsername": "bellapoarch",
        "authorNickname": null,
        "description": null,
        "views": null,
        "likes": null,
        "comments": null,
        "shares": null,
        "saves": null,
        "favorites": null,
        "durationSeconds": null,
        "postedAt": null,
        "scrapedAt": "2026-10-19T03:32:03.000Z",
        "error": "TikTok video not found or has been deleted (item doesn't exist)."
    }
]
```

***

### How It Works

1. **Input Normalization, Deduplication & Short Link Resolution**:
   - Validates each URL against canonical TikTok video URL patterns (`https://www.tiktok.com/@<user>/video/<id>`) and short link formats (`https://vm.tiktok.com/...`, `https://vt.tiktok.com/...`, `https://www.tiktok.com/t/...`).
   - Strips query parameters, tracking flags, and trailing slashes, and resolves short links to canonical URLs before scraping.
2. **Embedded JSON Extraction (Primary)**:
   - Extracts video metadata and engagement counters directly from `<script id="__UNIVERSAL_DATA_FOR_REHYDRATION__">` (`__DEFAULT_SCOPE__["webapp.video-detail"].itemInfo.itemStruct`) and `<script id="SIGI_STATE">` (`ItemModule`).
   - Prefers 64-bit integer strings in `statsV2` over legacy `stats` to avoid 32-bit signed integer overflow on videos with >2.14 billion views.
   - Automatically solves TikTok's `SlardarWAF` proof-of-work challenge cookie if triggered on an HTTP request, and enriches metadata via TikTok's official `/oembed` endpoint when needed.
3. **Headless Browser Fallback (Secondary)**:
   - Falls back to headless Puppeteer only if the embedded JSON state is unavailable from HTTP requests.
4. **Modest Concurrency & Backoff Retries**:
   - Processes URLs in parallel (default concurrency `4`) and retries failed requests up to `3` times with exponential backoff.

***

### Local Development & Testing

```bash
## Install dependencies
npm install

## Run unit tests
npm test

## Build TypeScript
npm run build

## Run Actor locally using Apify CLI
apify run
```

***

### Deployment to Apify Platform

```bash
## 1. Authenticate with your Apify account
apify login

## 2. Deploy the Actor to the Apify platform
apify push
```

***

### Summary of Field Availability in Testing

| Field | Public Availability | Source in Embedded JSON (`__UNIVERSAL_DATA_FOR_REHYDRATION__` / `SIGI_STATE`) |
| :--- | :--- | :--- |
| `videoUrl` | **Obtainable** | Canonical normalized URL (`https://www.tiktok.com/@<user>/video/<id>`). |
| `videoId` | **Obtainable** | Extracted from `itemStruct.id`. |
| `authorUsername` | **Obtainable** | Extracted from `itemStruct.author.uniqueId` (or oEmbed `author_unique_id`). |
| `authorNickname` | **Obtainable** | Extracted from `itemStruct.author.nickname` (or oEmbed `author_name`). |
| `description` | **Obtainable** | Extracted from `itemStruct.desc` (or oEmbed `title`). |
| `views` | **Obtainable** | Extracted from `itemStruct.statsV2.playCount` / `stats.playCount`. |
| `likes` | **Obtainable** | Extracted from `itemStruct.statsV2.diggCount` / `stats.diggCount`. |
| `comments` | **Obtainable** | Extracted from `itemStruct.statsV2.commentCount` / `stats.commentCount`. |
| `shares` | **Obtainable** | Extracted from `itemStruct.statsV2.shareCount` / `stats.shareCount`. |
| `saves` | **Obtainable** | Extracted from `itemStruct.statsV2.collectCount` / `stats.collectCount` (TikTok's bookmark/save counter). |
| `favorites` | **Obtainable** | Extracted from `itemStruct.statsV2.collectCount` / `stats.collectCount` (TikTok's "Add to Favorites" / bookmark counter shares the same `collectCount` field). |
| `durationSeconds` | **Obtainable** | Extracted from `itemStruct.video.duration`. |
| `postedAt` | **Obtainable** | Converted to ISO 8601 from `itemStruct.createTime` (Unix epoch seconds). |
| `scrapedAt` | **Obtainable** | ISO 8601 timestamp recorded at scrape completion. |
| `error` | **`null` on success** | Populated with a descriptive message when an input URL is invalid or the video is deleted/private/unavailable (in which case unavailable fields return `null`). |

# Actor input Schema

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

List of TikTok video URLs (e.g. https://www.tiktok.com/@<user>/video/<id> or short links https://vm.tiktok.com/... and https://www.tiktok.com/t/...) to collect engagement metrics for.

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

Apify Proxy settings. Residential proxies are recommended if plain requests are blocked by TikTok.

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

Maximum number of TikTok video URLs to process in parallel (conservative default between 3 and 5).

## `sessionCookie` (type: `string`):

Optional TikTok 'sessionid' cookie value if authenticated access is needed for restricted videos. Stored encrypted and never logged.

## Actor input object example

```json
{
  "videoUrls": [
    "https://www.tiktok.com/@tiktok/video/7106594312292453675",
    "https://www.tiktok.com/@zachking/video/6768504823336815877",
    "https://www.tiktok.com/@420doggface208/video/6876424179084709126"
  ],
  "proxyConfiguration": {
    "useApifyProxy": true
  },
  "maxConcurrency": 4
}
```

# 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/7106594312292453675",
        "https://www.tiktok.com/@zachking/video/6768504823336815877",
        "https://www.tiktok.com/@420doggface208/video/6876424179084709126"
    ],
    "proxyConfiguration": {
        "useApifyProxy": true
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("dwi_wahyu/tiktok-video-engagement-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/7106594312292453675",
        "https://www.tiktok.com/@zachking/video/6768504823336815877",
        "https://www.tiktok.com/@420doggface208/video/6876424179084709126",
    ],
    "proxyConfiguration": { "useApifyProxy": True },
}

# Run the Actor and wait for it to finish
run = client.actor("dwi_wahyu/tiktok-video-engagement-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/7106594312292453675",
    "https://www.tiktok.com/@zachking/video/6768504823336815877",
    "https://www.tiktok.com/@420doggface208/video/6876424179084709126"
  ],
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}' |
apify call dwi_wahyu/tiktok-video-engagement-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,dwi_wahyu/tiktok-video-engagement-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/84uB4uBPMo8JVSEZv/builds/JN3GUFjepIhvXOeOn/openapi.json
