For AI

How-to guides

How to export Douyin video comments in bulk

Two endpoints do it: Douyin video search, then Douyin video comments for each video you keep. The worked example below is 9 calls and costs $0.036; a failed call is not charged.

Updated

The job: you have a topic or a product name, and you want to know what people say under the Douyin videos about it. Search first, keep the videos that drew the most discussion, then read their comment sections a page at a time. You end with one table of comments, each with its text, the commenter, likes, reply count, time and, where Douyin shows it, the commenter's IP region.

No Douyin account, cookie or signature code is involved. Each call is an HTTPS request with your key.

Step by step

Step 1: find the videos

Call Douyin video search with query set to the words you would type into the Douyin search box. sort takes relevance (the default), latest or most_liked. One call returns about 20 videos, each with id, the caption in text, the author and metrics (likes, comments, shares, favorites). metrics.comments tells you which videos are worth opening.

curl -G "https://api.okdata.online/v1/douyin/videos/search" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=露营' \
  --data-urlencode 'sort=most_liked' \
  --data-urlencode 'fields=id,text,author.name,metrics.comments,published_at'

fields keeps only the fields you name. It does not change the price ($0.02 per call), but it keeps the response short when a model reads it.

Step 2: read the comments under each video

Pass a video's id to Douyin video comments. One call returns about 20 top-level comments for $0.002. Each one has text, author, likes, replies (how many replies sit under it), published_at and ip_location. For the next page, send page.next_cursor back as cursor, unchanged; stop when page.has_more is false.

curl -G "https://api.okdata.online/v1/douyin/videos/comments/list" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=7301234567890123456'

Step 3: put it together in Python

The script below searches once, keeps the 8 videos with the most comments, reads up to MAX_PAGES pages under each and writes a CSV. Every page is its own call, so the page cap is also your spending cap.

import csv
import os
import requests

API = "https://api.okdata.online"
HEADERS = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
MAX_PAGES = 1  # pages of comments per video; each page is one call


def get(path, **params):
    body = requests.get(API + path, headers=HEADERS, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']} (charged: {body['charged']})")
    return body


videos = get("/v1/douyin/videos/search", query="露营")["data"]["items"]
videos = sorted(videos, key=lambda v: v["metrics"]["comments"] or 0, reverse=True)[:8]

with open("douyin_comments.csv", "w", newline="", encoding="utf-8") as f:
    out = csv.writer(f)
    out.writerow(["video_id", "comment", "user", "likes", "replies", "ip_location", "published_at"])
    for v in videos:
        cursor = None
        for _ in range(MAX_PAGES):
            params = {"id": v["id"], **({"cursor": cursor} if cursor else {})}
            body = get("/v1/douyin/videos/comments/list", **params)
            for c in body["data"]["items"]:
                out.writerow([v["id"], c["text"], c["author"]["name"], c["likes"], c["replies"], c["ip_location"], c["published_at"]])
            if not body["page"]["has_more"]:
                break
            cursor = body["page"]["next_cursor"]

Raise MAX_PAGES to go deeper. Five pages under each of the 8 videos is 40 comment calls, $0.08 on top of the search.

Good to know

  • Retries without paying twice. Send an Idempotency-Key header (any random string you keep) with each call. If the network drops and you send the same request with the same key within 24 hours, you get the stored answer back with meta.replayed: true and no new charge.
  • Deleted videos are free. A video that no longer exists returns not_found and costs nothing; skip it and move on.
  • Counts can differ. Douyin folds some comments, so the number you collect can be lower than metrics.comments on the video.
  • Replies. You get each comment's reply count, not the reply text. Sort by replies to see which comments started a conversation, then open those videos in the app if you need the thread.
  • Sorting. Douyin's comment list comes in its own "hot" order; there is no newest-first option for comments.

For the opinions inside the comments, see how to turn Douyin comments into a sentiment summary. For one account's videos rather than a keyword, start from Douyin account videos instead of search.

What the example costs

One page of search results for 露营 (camping), then the first page of comments under the 8 videos with the most comments

EndpointCallsPriceSubtotal
Douyin video search1$0.02$0.02
Douyin video comments8$0.002$0.016
Total9$0.036

Prices in force when this page was built. A failed call costs nothing.

In your AI (MCP)

Connect the MCP server once, then say what you want. The agent finds these endpoints, reads their prices and calls them on your balance.

SaySearch Douyin for 露营 (camping), take the 8 videos with the most comments, get the first page of comments under each and give me one table: video, comment, likes, replies, time.

What the agent sends to the call tool first
{
  "endpoint": "douyin.videos.search",
  "params": {
    "query": "露营装备"
  },
  "idempotency_key": "<a new UUID>"
}

Set up the MCP server →

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp