使用 API 构建 TikTok 电子商务趋势跟踪器,让您可以实时监控病毒产品、趋势标签和新兴利基市场,以便您可以在竞争对手发现之前找到获胜产品。本教程将引导您搜索与电子商务相关的 TikTok 内容,从主题标签和标题中提取产品信号,以及构建一个按速度和参与度对趋势进行排名的评分系统。
前置条件
- 具有 TikTok 访问权限的 Scavio API 密钥(在 scavio.dev 上每月免费 250 个积分)
- Python 3.9+ 或 Node.js 18+
- 对电商产品研究的基本了解
操作指南
步骤 1: 定义产品发现搜索查询
建立一个展示病毒式产品的 TikTok 搜索查询列表。使用 dropshippers 和 DTC 品牌通常监控的主题标签式查询和产品类别关键字。包括广泛的趋势查询和特定领域的查询。
search_queries = [
'tiktok made me buy it',
'viral product 2026',
'amazon finds must have',
'small business check',
'dropshipping winning product',
'kitchen gadget viral',
'skincare routine viral',
'home organization hack',
]步骤 2: 在 TikTok 中搜索热门内容
查询每个产品发现查询的 Scavio TikTok 搜索端点。收集视频元数据,包括观看次数、点赞、分享、主题标签和发布日期。这些原始数据将成为您的趋势信号。
import requests
API_KEY = 'your_scavio_api_key'
def search_tiktok(query, count=20):
resp = requests.post(
'https://api.scavio.dev/api/v1/tiktok/search/videos',
headers={'Authorization': f'Bearer {API_KEY}'},
json={'query': query, 'count': count}
)
resp.raise_for_status()
return resp.json().get('videos', [])
all_videos = []
for q in search_queries:
videos = search_tiktok(q, count=20)
for v in videos:
v['search_query'] = q
all_videos.extend(videos)
print(f'Collected {len(all_videos)} videos across {len(search_queries)} queries')步骤 3: 按参与度提取主题标签并对其进行排名
从所有收集的视频中解析主题标签,并汇总每个主题标签的参与度指标。出现在多个高参与度视频中的主题标签标志着流行产品或利基市场。
from collections import defaultdict
hashtag_stats = defaultdict(lambda: {'total_views': 0, 'total_likes': 0, 'video_count': 0})
for v in all_videos:
for tag in v.get('hashtags', []):
tag_lower = tag.lower()
hashtag_stats[tag_lower]['total_views'] += v.get('views', 0)
hashtag_stats[tag_lower]['total_likes'] += v.get('likes', 0)
hashtag_stats[tag_lower]['video_count'] += 1
# Rank by a composite score: views * sqrt(video_count)
import math
ranked = sorted(
hashtag_stats.items(),
key=lambda x: x[1]['total_views'] * math.sqrt(x[1]['video_count']),
reverse=True
)
print('Top trending hashtags:')
for tag, stats in ranked[:15]:
print(f' #{tag}: {stats["total_views"]:,} views, {stats["video_count"]} videos')步骤 4: 对产品趋势进行评分和分类
根据参与速度(每个视频的观看次数)、广度(唯一视频的数量)和新近度,为每个主题标签集群分配趋势分数。根据分数阈值将趋势分类为新兴趋势、峰值趋势或饱和趋势。
def score_trend(stats):
views_per_video = stats['total_views'] / max(stats['video_count'], 1)
breadth = stats['video_count']
score = (views_per_video / 1000) * math.sqrt(breadth)
if score > 100 and breadth < 10:
phase = 'emerging'
elif score > 50:
phase = 'peaking'
else:
phase = 'saturated'
return {'score': round(score, 1), 'phase': phase, 'views_per_video': int(views_per_video)}
trends = []
for tag, stats in ranked[:30]:
trend = score_trend(stats)
trend['hashtag'] = tag
trend['total_views'] = stats['total_views']
trend['video_count'] = stats['video_count']
trends.append(trend)
for t in trends[:10]:
print(f'#{t["hashtag"]} | score: {t["score"]} | phase: {t["phase"]} | {t["views_per_video"]:,} views/vid')步骤 5: 出口趋势报告
将评分趋势保存到 JSON 文件,您可以将其输入到产品研究工作流程、Slack 警报或仪表板中。包含原始数据,以便您稍后可以使用不同的阈值重新评分。
import json
report = {
'scan_date': '2026-05-12',
'total_videos_analyzed': len(all_videos),
'unique_hashtags': len(hashtag_stats),
'top_trends': trends,
}
with open('tiktok_ecommerce_trends.json', 'w') as f:
json.dump(report, f, indent=2)
print(f'Exported {len(trends)} trends to tiktok_ecommerce_trends.json')Python 示例
import requests
import math
import json
from collections import defaultdict
API_KEY = 'your_scavio_api_key'
search_queries = [
'tiktok made me buy it',
'viral product 2026',
'amazon finds must have',
'dropshipping winning product',
]
def search_tiktok(query, count=20):
resp = requests.post(
'https://api.scavio.dev/api/v1/tiktok/search/videos',
headers={'Authorization': f'Bearer {API_KEY}'},
json={'query': query, 'count': count}
)
resp.raise_for_status()
return resp.json().get('videos', [])
all_videos = []
for q in search_queries:
videos = search_tiktok(q, count=20)
for v in videos:
v['search_query'] = q
all_videos.extend(videos)
hashtag_stats = defaultdict(lambda: {'total_views': 0, 'total_likes': 0, 'video_count': 0})
for v in all_videos:
for tag in v.get('hashtags', []):
tag_lower = tag.lower()
hashtag_stats[tag_lower]['total_views'] += v.get('views', 0)
hashtag_stats[tag_lower]['total_likes'] += v.get('likes', 0)
hashtag_stats[tag_lower]['video_count'] += 1
ranked = sorted(
hashtag_stats.items(),
key=lambda x: x[1]['total_views'] * math.sqrt(x[1]['video_count']),
reverse=True
)
trends = []
for tag, stats in ranked[:30]:
vpv = stats['total_views'] / max(stats['video_count'], 1)
score = (vpv / 1000) * math.sqrt(stats['video_count'])
phase = 'emerging' if score > 100 and stats['video_count'] < 10 else ('peaking' if score > 50 else 'saturated')
trends.append({
'hashtag': tag,
'score': round(score, 1),
'phase': phase,
'total_views': stats['total_views'],
'video_count': stats['video_count'],
})
report = {
'scan_date': '2026-05-12',
'total_videos': len(all_videos),
'top_trends': trends,
}
with open('tiktok_ecommerce_trends.json', 'w') as f:
json.dump(report, f, indent=2)
print(f'Analyzed {len(all_videos)} videos, found {len(trends)} trends')
for t in trends[:5]:
print(f' #{t["hashtag"]} | score: {t["score"]} | {t["phase"]}')JavaScript 示例
const fs = require('fs');
const API_KEY = 'your_scavio_api_key';
const searchQueries = [
'tiktok made me buy it',
'viral product 2026',
'amazon finds must have',
'dropshipping winning product',
];
async function searchTiktok(query, count = 20) {
const resp = await fetch('https://api.scavio.dev/api/v1/tiktok/search/videos', {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ query, count }),
});
const data = await resp.json();
return data.videos || [];
}
async function main() {
const allVideos = [];
for (const q of searchQueries) {
const videos = await searchTiktok(q, 20);
videos.forEach(v => { v.search_query = q; });
allVideos.push(...videos);
}
const hashtagStats = {};
for (const v of allVideos) {
for (const tag of v.hashtags || []) {
const t = tag.toLowerCase();
if (!hashtagStats[t]) hashtagStats[t] = { totalViews: 0, totalLikes: 0, videoCount: 0 };
hashtagStats[t].totalViews += v.views || 0;
hashtagStats[t].totalLikes += v.likes || 0;
hashtagStats[t].videoCount += 1;
}
}
const ranked = Object.entries(hashtagStats)
.sort((a, b) => b[1].totalViews * Math.sqrt(b[1].videoCount) - a[1].totalViews * Math.sqrt(a[1].videoCount))
.slice(0, 30);
const trends = ranked.map(([tag, stats]) => {
const vpv = stats.totalViews / Math.max(stats.videoCount, 1);
const score = (vpv / 1000) * Math.sqrt(stats.videoCount);
const phase = score > 100 && stats.videoCount < 10 ? 'emerging' : score > 50 ? 'peaking' : 'saturated';
return { hashtag: tag, score: Math.round(score * 10) / 10, phase, totalViews: stats.totalViews, videoCount: stats.videoCount };
});
const report = { scan_date: '2026-05-12', total_videos: allVideos.length, top_trends: trends };
fs.writeFileSync('tiktok_ecommerce_trends.json', JSON.stringify(report, null, 2));
console.log(`Analyzed ${allVideos.length} videos, found ${trends.length} trends`);
trends.slice(0, 5).forEach(t => console.log(` #${t.hashtag} | score: ${t.score} | ${t.phase}`));
}
main();预期输出
Analyzed 80 videos, found 30 trends
#tiktokmademebuyit | score: 245.3 | peaking
#viralproduct | score: 189.7 | peaking
#amazonfind | score: 134.2 | emerging
#kitchengadget | score: 98.4 | peaking
#dropshipping2026 | score: 76.1 | emerging