建立 TikTok 品牌监控管道,搜索品牌提及、从相关视频中提取评论并对情绪进行分类。总成本:监控 10 个品牌关键词每天 0.25-0.50 美元。
前置条件
- Scavio API 密钥
- Python 3.8+
- 可选:用于情绪的 OpenAI API 密钥
- 通知渠道(Slack webhook、电子邮件)
操作指南
步骤 1: 搜索品牌提及
搜索提及您品牌的 TikTok 视频。
Python
import requests, os
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
def search_brand(brand_name, pages=2):
videos = []
cursor = 0
for _ in range(pages):
data = requests.post('https://api.scavio.dev/api/v1/tiktok/search/videos',
headers=HEADERS,
json={'keyword': brand_name, 'count': 20, 'cursor': cursor}).json()['data']
videos.extend(data.get('videos', []))
if not data.get('has_more'): break
cursor = data['cursor']
return videos步骤 2: 从高参与度视频中提取评论
从参与度较高的视频中提取评论。
Python
def get_comments(video_id, pages=2):
comments = []
cursor = 0
for _ in range(pages):
data = 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(data.get('comments', []))
if not data.get('has_more'): break
cursor = data.get('cursor', cursor + 20)
return comments
# Only analyze videos with significant engagement
high_engagement = [v for v in videos if v['stats']['playCount'] > 1000]
for v in high_engagement[:5]:
comments = get_comments(v['id'])
print(f"{v['desc'][:40]}: {len(comments)} comments")Python 示例
Python
import requests, os, json
from datetime import date
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
def brand_monitor(brand, keywords=None):
if keywords is None:
keywords = [brand, f'{brand} review', f'{brand} alternative']
report = {'date': date.today().isoformat(), 'brand': brand, 'mentions': []}
for kw in keywords:
data = requests.post('https://api.scavio.dev/api/v1/tiktok/search/videos',
headers=HEADERS,
json={'keyword': kw, 'count': 20, 'cursor': 0}).json()['data']
for v in data.get('videos', []):
if v['stats']['playCount'] > 500:
report['mentions'].append({
'keyword': kw, 'desc': v['desc'][:100],
'plays': v['stats']['playCount'],
'likes': v['stats']['diggCount'],
'comments': v['stats']['commentCount'],
})
report['total_mentions'] = len(report['mentions'])
return report
report = brand_monitor('mybrand')
print(f"{report['total_mentions']} high-engagement mentions found")JavaScript 示例
JavaScript
const H = {'Authorization': `Bearer ${process.env.SCAVIO_API_KEY}`, 'Content-Type': 'application/json'};
async function brandMonitor(brand) {
const keywords = [brand, `${brand} review`, `${brand} alternative`];
const mentions = [];
for (const kw of keywords) {
const r = await fetch('https://api.scavio.dev/api/v1/tiktok/search/videos', {
method: 'POST', headers: H,
body: JSON.stringify({keyword: kw, count: 20, cursor: 0})
}).then(r => r.json());
(r.data.videos || []).filter(v => v.stats.playCount > 500).forEach(v =>
mentions.push({keyword: kw, desc: v.desc?.slice(0, 100),
plays: v.stats.playCount, likes: v.stats.diggCount})
);
}
console.log(`${mentions.length} high-engagement mentions found`);
return mentions;
}
brandMonitor('mybrand');预期输出
JSON
Daily brand monitoring report with high-engagement TikTok mentions, engagement metrics, and optional sentiment classification.