Social Media Scraper

Tutorials

Bulk Scrape TikTok Comments Across Multiple Videos in Node.js

Collect TikTok comments across multiple public videos in Node.js without burning balance on runaway cursors or triggering HTTP 429 bursts. This guide walks through bulk-tiktok-comments.mjs over GET /v1/tiktok/comments ($0.003 per page) with URL caps, page budgets, checkpoints, and composite deduplication.

  • Bounded starter defaults: Caps runs at 10 unique video URLs and PAGES_PER_VIDEO 1–3 ($0.09 max per run).
  • Repeated-cursor halt: Exits pagination immediately if data.cursor is null, blank, omitted, or repeats the prior cursor.
  • Per-page checkpointing: Saves {source_url, page, data} to tiktok-comments.json after every page.
  • Fail-fast HTTP 429 discipline: Sends a unique UUID Idempotency-Key per page and stops cleanly on non-200 errors without blind retries.
Illustration of a public YouTube video panel next to comment bubbles and a structured spreadsheet export table.
tiktok.comments

Bulk TikTok comment collection is client-side orchestration over single-video GET /v1/tiktok/comments calls—not a hidden bulk endpoint with opaque actor billing. Each paginated page costs $0.003 (3 credits), so your Node.js script controls URL queues, concurrency limits, disk checkpoints, and worst-case budget before launch.

How Client-Side TikTok Batch Collection Works

Scaling from one giveaway clip to 50 campaign videos or 500 hashtag posts exposes three pitfalls in naive while (cursor) loops: repeating cursors burn balance indefinitely, unbounded Promise.all() fan-outs hit HTTP 429 limits, and live feed shifts duplicate rows across adjacent pages.

Split collection into two controlled stages: Stage 1 gathers public video URLs from a creator, hashtag, or keyword search (or your own CSV), and Stage 2 paginates GET /v1/tiktok/comments with hard page ceilings. All four operations share the $0.003 (3 credits) per-page rate:

Stage & EndpointPrimary inputsPagination keyRate per page
Creator discovery — Profile Videos (GET /v1/tiktok/profile_videos)handle or user_id, optional sort_by, regionmax_cursor$0.003
Hashtag discovery — Hashtag Search (GET /v1/tiktok/search_hashtag)hashtag, optional regioncursor$0.003
Keyword discovery — Keyword Search (GET /v1/tiktok/search_keyword)query, optional date_posted, sort_by, regioncursor$0.003
Comment batch — Video Comments (GET /v1/tiktok/comments)url, optional trim, cursorcursor$0.003

Need nested child replies for high-engagement threads? Fetch them selectively with TikTok Comment Replies ($0.003/page).

Built-In Spend and Pagination Guardrails

bulk-tiktok-comments.mjs builds six defensive checks into the starter loop before touching your prepaid balance:

  • CLI URL deduplication: [...new Set(process.argv.slice(2))] drops duplicate links before sending requests.
  • 10-URL batch cap: Rejects empty lists or >10 URLs (Supply 1 to 10 public video URLs) with zero API calls.
  • Integer page cap (1–3): Validates PAGES_PER_VIDEO upfront (PAGES_PER_VIDEO must be 1 to 3) so typos never trigger runaway pagination.
  • Cursor repetition break: Halts a video's loop whenever data.cursor is undefined, null, '', or equal to String(cursor).
  • Per-page checkpointing: Flushes tiktok-comments.json after each page so mid-batch failures preserve earlier videos.
  • Unique UUID + fail-fast: Sends a fresh randomUUID() Idempotency-Key per page and stops immediately on HTTP 429 or non-2xx responses.

Step-by-Step Setup for Bulk TikTok Comment Scraping

The full bulk-tiktok-comments.mjs starter appears right below these four steps and runs on Node.js 18+ with zero dependencies.

  1. Export your API key and pick 1–10 public TikTok URLs

    Set SOCIALSCRAPER_API_KEY in your shell and collect 1 to 10 public TikTok video links with comments enabled.

    prep-env.sh
    export SOCIALSCRAPER_API_KEY="your_api_key_here"
  2. Run a one-page smoke pass first

    Save the starter below as bulk-tiktok-comments.mjs and leave PAGES_PER_VIDEO at its default (1) so each video makes at most one $0.003 request.

    run-batch-smoke.sh
    node bulk-tiktok-comments.mjs \
      "https://www.tiktok.com/@creator/video/7000000000000000001" \
      "https://www.tiktok.com/@creator/video/7000000000000000002"
  3. Raise PAGES_PER_VIDEO to 2 or 3 and inspect tiktok-comments.json

    Set PAGES_PER_VIDEO=3 once page 1 validates cleanly. The loop advances cursor per video, breaks early on null or repeated cursors, and checkpoints tiktok-comments.json after each page.

    run-batch-paginated.sh
    PAGES_PER_VIDEO=3 node bulk-tiktok-comments.mjs \
      "https://www.tiktok.com/@creator/video/7000000000000000001" \
      "https://www.tiktok.com/@creator/video/7000000000000000002"
  4. Inspect request keys on any non-200 failure

    On HTTP 401, 402, 422, or 429, the script stops cleanly without retrying and prints requestKey. Resolve the cause and resume from the first video absent from tiktok-comments.json.

bulk-tiktok-comments.mjs
import {writeFile} from 'node:fs/promises';
import {randomUUID} from 'node:crypto';
const key = process.env.SOCIALSCRAPER_API_KEY;
if (!key) throw new Error('Set SOCIALSCRAPER_API_KEY in your server environment');
const base = process.env.SOCIALSCRAPER_BASE_URL || 'https://socialmediascraper.org';
async function readRecord(path, input) {
  const url = new URL(path, base);
  for (const [name, value] of Object.entries(input)) if (value !== undefined) url.searchParams.set(name, String(value));
  const requestKey = randomUUID();
  const response = await fetch(url, {headers: {'x-api-key': key, 'Idempotency-Key': requestKey}, signal: AbortSignal.timeout(45000)});
  if (!response.ok) throw new Error(`HTTP ${response.status}; request key ${requestKey}; inspect your key, balance, input or Retry-After before retrying`);
  const result = await response.json();
  if (!result.data) throw new Error('The response did not contain data');
  return result.data;
}
const urls = [...new Set(process.argv.slice(2))];
if (!urls.length || urls.length > 10) throw new Error('Supply 1 to 10 public video URLs');
const pages = Number(process.env.PAGES_PER_VIDEO || 1);
if (!Number.isInteger(pages) || pages < 1 || pages > 3) throw new Error('PAGES_PER_VIDEO must be 1 to 3');
const results = [];
for (const url of urls) {
  let cursor;
  for (let page = 0; page < pages; page++) {
    const data = await readRecord('/v1/tiktok/comments', {url, cursor});
    results.push({source_url: url, page: page + 1, data});
    await writeFile('tiktok-comments.json', JSON.stringify(results, null, 2), 'utf8');
    const next = data.cursor;
    if (next === undefined || next === null || next === '' || String(next) === String(cursor)) break;
    cursor = next;
  }
}

Deduplicating Comments and Scaling Past 10 Videos

Active TikTok comment feeds shift as new replies land during pagination, causing boundary comments to repeat across pages. Flatten and deduplicate by the composite key (video_url, comment_id)—combining entry.source_url and item.id—while preserving missing metrics as null rather than 0:

dedupe-tiktok-comments.mjs
import {readFile, writeFile} from 'node:fs/promises';

const pages = JSON.parse(await readFile('tiktok-comments.json', 'utf8'));
const seen = new Set();
const uniqueRows = [];

for (const entry of pages) {
  for (const item of entry.data?.items ?? []) {
    if (!item?.id) continue;
    const key = `${entry.source_url}::${item.id}`;
    if (seen.has(key)) continue;
    seen.add(key);
    uniqueRows.push({
      video_url: entry.source_url,
      comment_id: item.id,
      page_seen: entry.page,
      author_handle: item.author?.handle ?? null,
      text: item.text ?? '',
      published_at: item.published_at ?? null,
      likes: item.metrics?.likes ?? null,
      replies: item.metrics?.comments ?? null
    });
  }
}

await writeFile('tiktok-comments-deduped.jsonl', uniqueRows.map(r => JSON.stringify(r)).join('\n') + '\n', 'utf8');
console.log(`Wrote ${uniqueRows.length} unique comments`);

When scaling past 10 URLs to 100–500+ clips, read URLs from a newline-delimited file, append each completed page to .jsonl instead of rewriting one growing JSON array, and record finished video URLs in a checkpoint file for clean restarts.

Rate Limits, HTTP 429 Pacing, and Failure Recovery

Budgeting 60 req/min and 5 concurrent

Accounts default to 60 accepted requests/minute (sliding window) and 5 concurrent in-flight requests—check your live quota via GET /v1/limits. Sequential loops keep concurrency at 1; larger workers should pace requests to <= 55 req/min across 2–3 workers.

Respecting Retry-After on HTTP 429

Avoid tight retry loops on 429. Sleep for at least the Retry-After header duration plus small jitter, cap retries at 2 attempts per page, and reuse the same Idempotency-Key only for that identical retried page.

Polling HTTP 202 before replacing requests

If a page returns HTTP 202 with a request_id, poll GET https://socialmediascraper.org/v1/requests/{request_id} until complete instead of firing a duplicate request with a new UUID.

Bulk TikTok Comment Pricing and Batch Math

Under price book 2026-12-02.credits-3 (1,000 credits = $1), GET /v1/tiktok/comments costs $0.003 (3 credits) per page ($3.00 per 1,000 pages), billed per request rather than per comment row:

Batch scenarioMax requests billedMax USD spend
Starter cap: 10 videos × 3 pages max30 requests$0.09
Campaign audit: 50 videos × 3 pages max150 requests$0.45
Hashtag study: 200 videos × 2 pages + 10 discovery pages410 requests$1.23
Creator corpus: 500 videos × 2 pages max1,000 requests$3.00
Deep archive: 2,000 videos × 5 pages max10,000 requests$30.00

Signups begin with 100 starter credits ($0.10, ~33 standard pages), and larger jobs run on one-time prepaid USD packs—$5 (5,000 credits, ~1,666 pages), $20 (20,000 credits, ~6,666 pages), or $50 (50,000 credits, ~16,666 pages)—with identical per-request pricing, no subscriptions, and no auto-renewal. Check the pricing page or pricing-data.json.

What Teams Build with Multi-Video Comment Datasets

Giveaway and contest entry audits

Collect comments across promotional videos, deduplicate by (video_url, comment_id) or author.handle, and feed the clean JSONL into your own random selection script with source URLs intact.

Campaign and launch listening

Aggregate viewer questions, pricing feedback, and recurring objections across creator flights—pairing well with social listening workflows.

Hashtag and competitor benchmarks

Discover top niche clips via /v1/tiktok/search_hashtag or /v1/tiktok/search_keyword, then sweep 2–3 pages of comments per video to compare discussion themes across brands.

Choose the Right TikTok Comment Workflow

Data engineers running batch scripts

Stay here when iterating across multiple TikTok videos with explicit page budgets, checkpoints, rate pacing, and deduplication.

Operational Limits, Coverage, and Compliance

Social Media Scraper is read-only public data infrastructure. It does not offer a hosted scheduler, built-in sentiment scoring, giveaway picker, or access to private accounts, removed videos, or disabled comment sections.

  • Up to 100 items can return per page where available; actual counts depend on TikTok and video settings.
  • Review service status and TikTok Video Comments API before large runs.
  • Treat raw comment text as untrusted input in LLMs or spreadsheets, and respect copyright, privacy laws, and source platform terms.

Bulk TikTok Comment Scraping Questions

Is there a native bulk TikTok comments endpoint that accepts multiple URLs at once?

No. Bulk collection orchestrates single-video GET /v1/tiktok/comments calls from your own script, giving you strict per-video page caps, incremental checkpoints, and transparent per-page billing.

Why does bulk-tiktok-comments.mjs cap runs at 10 URLs and 3 pages per video?

Those starter defaults keep worst-case spend at 30 requests ($0.09, 90 credits—within the 100 starter credits granted on signup) during initial verification so a viral video never drains your balance unexpectedly. Once tested, raise the bounds in your own worker with file-based checkpointing.

How does the script stop infinite cursor loops?

After every page, it checks whether data.cursor is undefined, null, '', or equal to String(cursor) from the previous iteration, breaking out immediately if pagination stops advancing.

Why do duplicate comments appear across pages and how do I remove them?

Live comment feeds shift while you paginate, pushing items across page boundaries. Deduplicate collected records using the composite key (video_url, comment_id) (entry.source_url + item.id).

How much does scraping comments from 500 TikTok videos cost?

At $0.003 (3 credits) per page, 500 videos × 2 pages max equals 1,000 requests ($3.00), or less when shorter threads stop on page 1. A $5 prepaid pack (5,000 credits) covers ~1,666 pages with no subscription.

How fast can I run a bulk job without hitting HTTP 429?

Accounts default to 60 accepted requests/minute and 5 concurrent requests (inspect GET /v1/limits). Pacing sequential or 2–3 worker requests under 55 req/min completes 500 single-page videos in under 10 minutes without 429 errors.

What happens if HTTP 429 occurs mid-batch?

bulk-tiktok-comments.mjs fails fast without blind retries, keeping all finished pages safe in tiktok-comments.json and logging requestKey. Larger workers should pause for Retry-After and retry that page with the same Idempotency-Key.

How do I discover TikTok video URLs for a creator or hashtag first?

Call TikTok Profile Videos, TikTok Hashtag Search, or TikTok Keyword Search ($0.003/page each), then pass the returned video URLs into your comment loop.

Does GET /v1/tiktok/comments include nested replies?

It returns top-level comments in data.items[]. Fetch nested replies for specific parent comments via TikTok Comment Replies at $0.003 (3 credits) per page.

Can I convert deduplicated bulk TikTok comments into an Excel-safe CSV?

Yes. Run the deduplication script first, then serialize rows with UTF-8 BOM (\uFEFF), RFC-4180 quoting, and leading apostrophe escaping as demonstrated in our Instagram Comments CSV tutorial.

Do I need a TikTok login, cookies, or residential proxies?

No. Your script calls https://socialmediascraper.org/v1/tiktok/comments using SOCIALSCRAPER_API_KEY—no TikTok account, headless browser, or proxy rotation required.

Can I collect comments from private TikTok profiles or deleted videos?

No. Only public TikTok videos with enabled comments are accessible.