Answers
How do I export Douyin video comments for sentiment analysis?
Short answer
Call the okdata Douyin video comments endpoint with each video ID and follow the cursor; a page of about 20 comments costs $0.002, so 1,000 comments take 50 calls and cost $0.10. Each comment has text, likes, reply count, time and IP location, ready for a sentiment model.
A product team launched a new phone case and wants to know how Douyin viewers react: what they praise, what they mock, which regions care. The raw material is the comment sections of the 30 biggest videos about it, a few thousand comments. Scrapers often get only the caption, or block with "account blocked" halfway through. The API route is three steps.
1. Pick the videos
Use Douyin video search with sort=most_liked, or turn known share links into IDs with video detail. Each video's metrics.comments tells you how big its comment section is.
2. Pull the comments
Douyin video comments takes the video id and an optional sort (hot or latest). Each comment has text, published_at, likes, replies (the number of replies under it), ip_location (the province Douyin shows) and the commenter.
3. Score them
Clean the text, then run a sentiment model or an LLM with a fixed label set, and weight each comment by its likes: a complaint with 2,000 likes speaks for more people than one with none.
Cost
| Job | Calls | Cost |
|---|---|---|
| Find 40 videos | 2 search pages | $0.04 |
| 30 videos × 5 comment pages | 150 | $0.30 |
| 1,000 comments, any video | 50 | $0.10 |
Script
import csv, os, requests
URL = "https://api.okdata.online/v1/douyin/videos/comments/list"
HEAD = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
with open("douyin_comments.csv", "w", newline="", encoding="utf-8-sig") as f:
w = csv.writer(f)
w.writerow(["video_id", "published_at", "text", "likes", "replies", "ip_location"])
for vid in ["7301234567890123456"]:
params = {"id": vid, "sort": "hot"}
for _ in range(5):
body = requests.get(URL, headers=HEAD, params=params, timeout=60).json()
for c in body["data"]["items"]:
w.writerow([vid, c["published_at"], c["text"], c["likes"], c["replies"], c["ip_location"]])
if not body["page"]["has_more"]:
break
params["cursor"] = body["page"]["next_cursor"]
Before you score
- Douyin writes emoji as codes like
[捂脸]or[赞]inside the text. Map them to sentiment hints or strip them; many models misread them. - Top-level comments only. The video's comment counter also counts replies, so you will collect fewer rows than it shows;
repliestells you where the long threads are. - Short comments ("哈哈哈", "求链接") are common. Decide up front whether purchase-intent comments count as positive.
- IP location is the province Douyin displays, not a precise location.
Alternatives
For one video, scrolling and copying is fine. MediaCrawler and similar tools collect comments and replies with a logged-in account. Social listening suites score sentiment for you but cost far more per month. The word-of-mouth page shows the full report, including Xiaohongshu and Weibo.
Updated