通过 Scavio API 提取 TikTok 视频评论,包括文本、点赞、回复计数和用户信息,价格为 0.005 美元/页。顶级评论和线索回复的单独端点。使用数字光标分页。
前置条件
- Scavio API 密钥
- 目标视频 ID (aweme_id)
- Python 3.8+ 或 Node.js 18+
操作指南
步骤 1: 获取视频评论
使用视频的 aweme_id 调用视频/评论端点。
Python
import requests, os
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
resp = requests.post('https://api.scavio.dev/api/v1/tiktok/video/comments',
headers=HEADERS,
json={'aweme_id': '7123456789', 'count': 20, 'cursor': 0})
data = resp.json()['data']
for c in data.get('comments', []):
print(f"{c['user']['unique_id']}: {c['text'][:60]}")
print(f" Likes: {c['digg_count']}, Replies: {c.get('reply_comment_total', 0)}")步骤 2: 获取评论的回复
使用comment/replies端点和comment_id进行线程讨论。
Python
comment_id = data['comments'][0]['cid']
replies = requests.post(
'https://api.scavio.dev/api/v1/tiktok/video/comments/replies',
headers=HEADERS,
json={'aweme_id': '7123456789', 'comment_id': comment_id,
'count': 20, 'cursor': 0}).json()['data']
for r in replies.get('comments', []):
print(f" Reply: {r['text'][:60]}")步骤 3: 通过评论分页
增加光标以获取更多评论页。
Python
cursor = data.get('cursor', 0)
if data.get('has_more'):
page2 = requests.post(
'https://api.scavio.dev/api/v1/tiktok/video/comments',
headers=HEADERS,
json={'aweme_id': '7123456789', 'count': 20,
'cursor': cursor}).json()['data']
print(f'Page 2: {len(page2.get("comments", []))} comments')Python 示例
Python
import requests, os
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
def get_comments(video_id, max_pages=5):
comments = []
cursor = 0
for _ in range(max_pages):
resp = requests.post('https://api.scavio.dev/api/v1/tiktok/video/comments',
headers=HEADERS,
json={'aweme_id': video_id, 'count': 20, 'cursor': cursor}).json()['data']
comments.extend(resp.get('comments', []))
if not resp.get('has_more'):
break
cursor = resp.get('cursor', cursor + 20)
return comments
comments = get_comments('7123456789')
print(f'{len(comments)} comments extracted')JavaScript 示例
JavaScript
const H = {'Authorization': `Bearer ${process.env.SCAVIO_API_KEY}`, 'Content-Type': 'application/json'};
async function getComments(videoId, maxPages = 5) {
const comments = [];
let cursor = 0;
for (let i = 0; i < maxPages; i++) {
const r = await fetch('https://api.scavio.dev/api/v1/tiktok/video/comments', {
method: 'POST', headers: H,
body: JSON.stringify({aweme_id: videoId, count: 20, cursor})
}).then(r => r.json());
comments.push(...(r.data.comments || []));
if (!r.data.has_more) break;
cursor = r.data.cursor || cursor + 20;
}
return comments;
}
getComments('7123456789').then(c => console.log(`${c.length} comments`));预期输出
JSON
Array of comment objects with text, user info, like count, reply count, and timestamps. Separate reply extraction for threaded discussions.