Build a TikTok brand monitoring pipeline that searches for brand mentions, extracts comments from relevant videos, and classifies sentiment. Total cost: $0.25-0.50/day for monitoring 10 brand keywords.
Prerequisites
- Scavio API key
- Python 3.8+
- Optional: OpenAI API key for sentiment
- Notification channel (Slack webhook, email)
Walkthrough
Step 1: Search for brand mentions
Search TikTok videos mentioning your brand.
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 videosStep 2: Extract comments from high-engagement videos
Pull comments from videos that got significant engagement.
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 Example
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 Example
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');Expected Output
Daily brand monitoring report with high-engagement TikTok mentions, engagement metrics, and optional sentiment classification.