Brandwatch 或 Sprout Social 等社交聆听工具每月收取 200-500 美元的 TikTok 监控费用。本教程使用 Scavio TikTok API 构建一个轻量级品牌提及跟踪器,该 API 在 cron 作业上运行,每月成本不到 1 美元。它会搜索您的品牌名称,跟踪新的提及,并在高参与度内容提及您的品牌时发送警报。每次搜索花费 1 个积分(0.005 美元)。
前置条件
- 已安装 Python 3.9+
- 请求已安装库
- 来自 scavio.dev 的 Scavio API 密钥
- cron 作业运行程序或调度程序
操作指南
步骤 1: 设置品牌提及搜索
在 TikTok 中搜索提及您品牌的视频。跟踪唯一的视频 ID 以检测每次运行时的新提及。
import requests, os, json, time
from pathlib import Path
API_KEY = os.environ['SCAVIO_API_KEY']
TT_URL = 'https://api.scavio.dev/api/v1/tiktok'
STATE_FILE = 'tiktok_mentions_state.json'
def load_state() -> dict:
if Path(STATE_FILE).exists():
return json.loads(Path(STATE_FILE).read_text())
return {'seen_ids': [], 'total_mentions': 0, 'last_run': ''}
def save_state(state: dict):
Path(STATE_FILE).write_text(json.dumps(state, indent=2))
def search_brand(brand_name: str, count: int = 20) -> list:
resp = requests.post(f'{TT_URL}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'},
json={'keyword': brand_name, 'count': count, 'cursor': 0})
resp.raise_for_status()
videos = resp.json().get('data', {}).get('videos', [])
return [{
'id': v.get('id', ''),
'author': v.get('author', {}).get('uniqueId', ''),
'desc': v.get('desc', ''),
'plays': v.get('stats', {}).get('playCount', 0),
'likes': v.get('stats', {}).get('diggCount', 0),
'create_time': v.get('createTime', 0),
} for v in videos]
videos = search_brand('scavio')
print(f'Found {len(videos)} videos mentioning brand')步骤 2: 检测新的提及并评分重要性
将当前结果与之前看到的视频 ID 进行比较。通过参与度对新提及进行评分,以优先考虑值得关注的内容。
from datetime import datetime
def check_mentions(brand_name: str) -> dict:
state = load_state()
seen = set(state['seen_ids'])
videos = search_brand(brand_name)
new_mentions = [v for v in videos if v['id'] not in seen]
# Score new mentions by engagement
for v in new_mentions:
engagement = v['plays'] + v['likes'] * 10 # likes weighted higher
if engagement > 100_000:
v['priority'] = 'high'
elif engagement > 10_000:
v['priority'] = 'medium'
else:
v['priority'] = 'low'
# Update state
state['seen_ids'] = list(seen | {v['id'] for v in videos})
state['total_mentions'] += len(new_mentions)
state['last_run'] = datetime.now().isoformat()
save_state(state)
return {
'new_mentions': len(new_mentions),
'total_tracked': len(state['seen_ids']),
'high_priority': [v for v in new_mentions if v.get('priority') == 'high'],
'all_new': new_mentions
}
result = check_mentions('scavio')
print(f'New mentions: {result["new_mentions"]}')
print(f'High priority: {len(result["high_priority"])}')
for v in result['all_new'][:5]:
print(f' [{v["priority"]}] @{v["author"]}: {v["plays"]:,} plays - {v["desc"][:40]}')步骤 3: 设置带有成本跟踪的自动监控
按计划运行监控器并跟踪每月成本。按每天 4 次检查和 2 个品牌条款计算,每月费用低于 1.20 美元。
def daily_monitor(brand_terms: list) -> dict:
"""Run once per scheduled check (e.g., every 6 hours via cron)."""
all_new = []
credits_used = 0
for term in brand_terms:
result = check_mentions(term)
all_new.extend(result['all_new'])
credits_used += 1
time.sleep(0.3)
# Alert on high-priority mentions
high = [v for v in all_new if v.get('priority') == 'high']
if high:
print(f'ALERT: {len(high)} high-engagement mentions detected!')
for v in high:
print(f' @{v["author"]}: {v["plays"]:,} plays')
daily_cost = credits_used * 0.005
checks_per_day = 4
monthly_cost = daily_cost * checks_per_day * 30
print(f'\nCredits this run: {credits_used} (${daily_cost:.3f})')
print(f'Estimated monthly cost: ${monthly_cost:.2f}')
print(f'vs Brandwatch: $200+/month')
return {'new': len(all_new), 'high_priority': len(high), 'cost': daily_cost}
# Run with your brand terms
brand_terms = ['scavio', 'scavio api']
daily_monitor(brand_terms)
# Cron setup (every 6 hours):
# 0 */6 * * * cd /path/to/project && python tiktok_monitor.pyPython 示例
import requests, os, json, time
from pathlib import Path
API_KEY = os.environ['SCAVIO_API_KEY']
TT = 'https://api.scavio.dev/api/v1/tiktok'
def monitor(brand):
state_file = Path(f'{brand}_state.json')
seen = set(json.loads(state_file.read_text())['ids']) if state_file.exists() else set()
resp = requests.post(f'{TT}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'},
json={'keyword': brand, 'count': 20, 'cursor': 0})
videos = resp.json().get('data', {}).get('videos', [])
new_ids = [v for v in videos if v.get('id', '') not in seen]
seen.update(v.get('id', '') for v in videos)
state_file.write_text(json.dumps({'ids': list(seen)}))
print(f'{brand}: {len(new_ids)} new mentions')
for v in new_ids[:3]:
print(f' @{v.get("author",{}).get("uniqueId","")} {v.get("stats",{}).get("playCount",0):,} plays')
monitor('scavio')JavaScript 示例
const fs = require('fs');
const API_KEY = process.env.SCAVIO_API_KEY;
const TT = 'https://api.scavio.dev/api/v1/tiktok';
async function monitor(brand) {
const stateFile = `${brand}_state.json`;
const seen = new Set(fs.existsSync(stateFile) ? JSON.parse(fs.readFileSync(stateFile)).ids : []);
const resp = await fetch(`${TT}/search/videos`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ keyword: brand, count: 20, cursor: 0 })
});
const videos = (await resp.json()).data?.videos || [];
const newVids = videos.filter(v => !seen.has(v.id));
videos.forEach(v => seen.add(v.id));
fs.writeFileSync(stateFile, JSON.stringify({ ids: [...seen] }));
console.log(`${brand}: ${newVids.length} new mentions`);
newVids.slice(0, 3).forEach(v =>
console.log(` @${v.author?.uniqueId} ${v.stats?.playCount?.toLocaleString()} plays`));
}
monitor('scavio');预期输出
Found 20 videos mentioning brand
New mentions: 4
High priority: 1
[high] @techreviewer: 250,000 plays - Just discovered scavio for my AI age
[medium] @devtips: 15,000 plays - Using scavio search API in my n8n wor
[low] @codelearn: 800 plays - Tutorial: adding search to your bot wi
ALERT: 1 high-engagement mentions detected!
@techreviewer: 250,000 plays
Credits this run: 2 ($0.010)
Estimated monthly cost: $1.20
vs Brandwatch: $200+/month