TikTok impulse les tendances produits plus rapidement que toute autre plateforme — un produit peut passer d'inconnu à épuisé en quelques jours. Détecter les tendances tôt donne aux marques e-commerce et aux dropshippers un avantage crucial. Ce tutoriel construit un pipeline de détection des tendances utilisant l'API Scavio TikTok qui surveille les hashtags liés aux produits, suit la vélocité des vues et identifie les produits émergents avant leur pic. Le système analyse les taux de croissance des hashtags, les schémas d'adoption par les créateurs et les ratios d'engagement pour générer des scores de tendance. Chaque exécution de détection coûte 5 à 10 crédits ($0.025-0.05).
Prérequis
- Python 3.9+ installé
- bibliothèque requests installée
- Une clé API Scavio depuis scavio.dev
- Catégories de produits ou niches à surveiller
Parcours
Étape 1: Définir les catégories de suivi des produits
Configurez les catégories de produits et les termes de recherche associés à surveiller. Chaque catégorie comporte plusieurs mots-clés pour couvrir différents angles de la même tendance.
categories = {
'skincare': {
'keywords': ['skincare routine', 'skincare haul', 'skincare viral',
'skincare hack', 'skincare tiktok made me buy'],
'hashtags': ['skincareroutine', 'skincarehaul', 'tiktokmademebuyit']
},
'tech_gadgets': {
'keywords': ['tech gadget viral', 'amazon finds tech',
'tiktok gadget review', 'must have tech 2026'],
'hashtags': ['techfinds', 'amazontechfinds', 'gadgetreview']
},
'kitchen': {
'keywords': ['kitchen gadget tiktok', 'cooking hack viral',
'amazon kitchen finds', 'kitchen must have'],
'hashtags': ['kitchenhacks', 'kitchenfinds', 'cookingtiktok']
}
}
total_searches = sum(len(c['keywords']) + len(c['hashtags']) for c in categories.values())
print(f'{len(categories)} categories, {total_searches} total API calls')
print(f'Estimated cost per run: ${total_searches * 0.005:.2f}')Étape 2: Rechercher des vidéos de produits tendance
Pour chaque mot-clé, recherchez sur TikTok et collectez les données vidéo. Suivez les lectures, les likes et les dates de création pour calculer les métriques de vélocité.
import requests, os, time
API_KEY = os.environ['SCAVIO_API_KEY']
TIKTOK_URL = 'https://api.scavio.dev/api/v1/tiktok'
def search_tiktok(keyword: str, count: int = 20) -> list:
resp = requests.post(f'{TIKTOK_URL}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'},
json={'keyword': keyword, '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),
'comments': v.get('stats', {}).get('commentCount', 0),
'shares': v.get('stats', {}).get('shareCount', 0),
'create_time': v.get('createTime', 0),
'keyword': keyword
} for v in videos]Étape 3: Extraire les noms de produits des descriptions vidéo
Analysez les descriptions vidéo pour identifier les noms de produits et les marques spécifiques. Les vidéos mentionnent souvent le nom exact du produit, la marque ou l'ASIN Amazon.
import re
from collections import Counter
def extract_products(videos: list) -> Counter:
"""Extract product mentions from video descriptions."""
product_counter = Counter()
# Common patterns: "Product Name" in caps, @brand mentions, #productname
for v in videos:
desc = v.get('desc', '')
# Hashtag products (e.g., #CeraVe #StanleyCup)
hashtags = re.findall(r'#(\w+)', desc)
for tag in hashtags:
# Filter out generic tags
if len(tag) > 3 and tag.lower() not in {
'fyp', 'foryou', 'viral', 'trending', 'tiktok',
'skincare', 'review', 'haul', 'musthave'}:
product_counter[tag.lower()] += 1
# Brand mentions (capitalized words that look like brand names)
brands = re.findall(r'\b([A-Z][a-zA-Z]+(?:\s[A-Z][a-zA-Z]+)?)\b', desc)
for brand in brands:
if len(brand) > 3 and brand.lower() not in {'this', 'that', 'the', 'with'}:
product_counter[brand.lower()] += 1
return product_counter
# Example:
products = extract_products(search_tiktok('skincare viral'))
for product, count in products.most_common(10):
print(f' {product}: {count} mentions')Étape 4: Calculer les scores de vélocité des tendances
Notez chaque produit en fonction de la rapidité de croissance de ses mentions. Une vélocité de vues élevée associée à de nombreux créateurs uniques signale un produit tendance.
import statistics
from datetime import datetime
def calculate_trend_score(product: str, videos: list) -> dict:
relevant = [v for v in videos if product in v.get('desc', '').lower()]
if len(relevant) < 2:
return {'product': product, 'trend_score': 0, 'reason': 'Too few videos'}
total_plays = sum(v['plays'] for v in relevant)
total_engagement = sum(v['likes'] + v['comments'] + v['shares'] for v in relevant)
unique_creators = len(set(v['author'] for v in relevant))
# Recency: weight recent videos more heavily
now = time.time()
recency_scores = []
for v in relevant:
age_days = (now - v['create_time']) / 86400 if v['create_time'] > 0 else 30
recency_scores.append(max(0, 1 - (age_days / 30))) # 0-1, 1=today
avg_recency = statistics.mean(recency_scores)
# Composite trend score
play_score = min(total_plays / 100000, 40) # up to 40 points
creator_score = min(unique_creators * 5, 30) # up to 30 points
recency_score = avg_recency * 30 # up to 30 points
total_score = round(play_score + creator_score + recency_score, 1)
return {
'product': product,
'trend_score': total_score,
'total_plays': total_plays,
'unique_creators': unique_creators,
'video_count': len(relevant),
'avg_recency': round(avg_recency, 2)
}Étape 5: Exécuter le pipeline complet de détection des tendances
Combinez toutes les étapes en un seul pipeline qui scanne les catégories, extrait les produits, note les tendances et produit un rapport classé.
def detect_trends(categories: dict) -> list:
all_videos = []
credits_used = 0
for category, config in categories.items():
print(f'Scanning {category}...')
for keyword in config['keywords']:
videos = search_tiktok(keyword, count=20)
all_videos.extend(videos)
credits_used += 1
time.sleep(0.3)
# Extract and score products
product_counts = extract_products(all_videos)
trends = []
for product, count in product_counts.most_common(20):
if count >= 3: # minimum mention threshold
score = calculate_trend_score(product, all_videos)
if score['trend_score'] > 10:
trends.append(score)
trends.sort(key=lambda t: t['trend_score'], reverse=True)
print(f'\nDetected {len(trends)} trending products')
print(f'Credits used: {credits_used} (${credits_used * 0.005:.2f})')
for t in trends[:10]:
emoji_bar = '#' * int(t['trend_score'] / 5)
print(f' [{t["trend_score"]:5.1f}] {t["product"]}: '
f'{t["total_plays"]:,} plays, {t["unique_creators"]} creators '
f'{emoji_bar}')
return trends
trends = detect_trends(categories)Exemple Python
import os, requests, time, re
from collections import Counter
API_KEY = os.environ['SCAVIO_API_KEY']
TT = 'https://api.scavio.dev/api/v1/tiktok'
def search(keyword, count=20):
resp = requests.post(f'{TT}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'},
json={'keyword': keyword, 'count': count, 'cursor': 0})
return resp.json().get('data', {}).get('videos', [])
def detect_trends(keywords):
all_videos = []
for kw in keywords:
all_videos.extend(search(kw))
time.sleep(0.3)
products = Counter()
for v in all_videos:
for tag in re.findall(r'#(\w{4,})', v.get('desc', '')):
if tag.lower() not in {'fyp', 'foryou', 'viral', 'trending'}:
products[tag.lower()] += 1
print(f'Scanned {len(all_videos)} videos, found {len(products)} products')
for product, count in products.most_common(10):
print(f' {product}: {count} mentions')
return products
detect_trends(['skincare viral', 'amazon finds 2026', 'tiktok made me buy'])Exemple JavaScript
const API_KEY = process.env.SCAVIO_API_KEY;
const TT = 'https://api.scavio.dev/api/v1/tiktok';
async function searchTikTok(keyword) {
const resp = await fetch(`${TT}/search/videos`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ keyword, count: 20, cursor: 0 })
});
return (await resp.json()).data?.videos || [];
}
async function detectTrends(keywords) {
const products = {};
for (const kw of keywords) {
const videos = await searchTikTok(kw);
videos.forEach(v => {
const tags = (v.desc || '').match(/#(\w{4,})/g) || [];
tags.forEach(t => {
const tag = t.slice(1).toLowerCase();
if (!['fyp', 'foryou', 'viral'].includes(tag)) {
products[tag] = (products[tag] || 0) + 1;
}
});
});
}
Object.entries(products).sort((a, b) => b[1] - a[1]).slice(0, 10)
.forEach(([p, c]) => console.log(` ${p}: ${c} mentions`));
}
detectTrends(['skincare viral', 'amazon finds 2026']);Sortie attendue
Scanning skincare...
Scanning tech_gadgets...
Scanning kitchen...
Detected 8 trending products
Credits used: 12 ($0.06)
[ 78.5] cerave: 1,234,000 plays, 15 creators ################
[ 65.2] stanleycup: 890,000 plays, 12 creators #############
[ 52.1] dysonairwrap: 567,000 plays, 8 creators ###########
[ 45.8] theordinary: 445,000 plays, 9 creators #########
[ 38.4] airfryer: 334,000 plays, 7 creators ########
[ 31.0] laneige: 234,000 plays, 6 creators ######
[ 24.5] owala: 178,000 plays, 5 creators #####
[ 18.2] hexclad: 123,000 plays, 4 creators ####