The Scavio TikTok API provides two search endpoints: search/videos returns video results for a query with cursor-based pagination, and search/users returns creator profiles. Both use POST requests with Authorization: Bearer.
Prerequisites
- Python 3.9+ or Node.js 18+
- Scavio API key with TikTok access
Walkthrough
Step 1: Search TikTok videos by keyword
POST to /tiktok/search/videos with your query. Paginate with the cursor field.
import requests
API_KEY = "your-scavio-api-key"
def search_tiktok_videos(query: str, cursor: int = 0, count: int = 20) -> dict:
r = requests.post(
"https://api.scavio.dev/api/v1/tiktok/search/videos",
json={"query": query, "cursor": cursor, "count": count},
headers={"Authorization": f"Bearer {API_KEY}"},
timeout=20
)
r.raise_for_status()
return r.json()
result = search_tiktok_videos("ai coding tutorial")
videos = result.get("videos", [])
for v in videos:
print(v.get("desc"), v.get("stats", {}).get("playCount"))Step 2: Paginate through video results
Use the cursor from the response to fetch the next page. Continue until has_more is False.
def get_all_videos(query: str, max_pages: int = 5) -> list:
all_videos = []
cursor = 0
for page in range(max_pages):
result = search_tiktok_videos(query, cursor=cursor)
videos = result.get("videos", [])
all_videos.extend(videos)
print(f"Page {page + 1}: {len(videos)} videos (total: {len(all_videos)})")
if not result.get("has_more") or not videos:
break
cursor = result.get("cursor", cursor + len(videos))
return all_videos
videos = get_all_videos("ai coding tutorial", max_pages=3)
print(f"Total videos fetched: {len(videos)}")Step 3: Search TikTok users by keyword
POST to /tiktok/search/users to find creator profiles. Same cursor-based pagination.
def search_tiktok_users(query: str, cursor: int = 0) -> dict:
r = requests.post(
"https://api.scavio.dev/api/v1/tiktok/search/users",
json={"query": query, "cursor": cursor},
headers={"Authorization": f"Bearer {API_KEY}"},
timeout=20
)
r.raise_for_status()
return r.json()
result = search_tiktok_users("ai developer")
users = result.get("users", [])
for u in users:
print(u.get("nickname"), u.get("follower_count"), u.get("sec_uid"))Step 4: Parse and filter results
Extract key metrics and filter by minimum play count or follower count.
def filter_videos(videos: list, min_plays: int = 10000) -> list:
filtered = []
for v in videos:
plays = v.get("stats", {}).get("playCount", 0)
if plays >= min_plays:
filtered.append({
"id": v.get("id"),
"desc": v.get("desc", "")[:100],
"plays": plays,
"likes": v.get("stats", {}).get("diggCount", 0),
"comments": v.get("stats", {}).get("commentCount", 0),
"author": v.get("author", {}).get("uniqueId")
})
return sorted(filtered, key=lambda x: x["plays"], reverse=True)
top_videos = filter_videos(videos, min_plays=50000)
for v in top_videos[:5]:
print(f"{v['plays']:>10,} plays | @{v['author']} | {v['desc'][:60]}")Python Example
import requests
API_KEY = "your-scavio-api-key"
def search_videos(query: str, cursor: int = 0, count: int = 20) -> dict:
r = requests.post(
"https://api.scavio.dev/api/v1/tiktok/search/videos",
json={"query": query, "cursor": cursor, "count": count},
headers={"Authorization": f"Bearer {API_KEY}"},
timeout=20
)
r.raise_for_status()
return r.json()
def search_users(query: str, cursor: int = 0) -> dict:
r = requests.post(
"https://api.scavio.dev/api/v1/tiktok/search/users",
json={"query": query, "cursor": cursor},
headers={"Authorization": f"Bearer {API_KEY}"},
timeout=20
)
r.raise_for_status()
return r.json()
def collect_top_videos(query: str, min_plays: int = 10000, max_pages: int = 3) -> list:
all_videos = []
cursor = 0
for _ in range(max_pages):
result = search_videos(query, cursor=cursor)
batch = result.get("videos", [])
if not batch:
break
all_videos.extend(batch)
if not result.get("has_more"):
break
cursor = result.get("cursor", 0)
return sorted(
[{"id": v.get("id"), "desc": v.get("desc","")[:80],
"plays": v.get("stats",{}).get("playCount",0),
"likes": v.get("stats",{}).get("diggCount",0),
"author": v.get("author",{}).get("uniqueId")}
for v in all_videos if v.get("stats",{}).get("playCount",0) >= min_plays],
key=lambda x: x["plays"], reverse=True
)
if __name__ == "__main__":
print("=== Top Videos for 'ai coding tutorial' ===")
videos = collect_top_videos("ai coding tutorial", min_plays=50000)
for i, v in enumerate(videos[:10], 1):
print(f"{i:2}. {v['plays']:>10,} plays | @{v['author']:<20} | {v['desc'][:50]}")
print("\n=== Users matching 'ai developer' ===")
user_result = search_users("ai developer")
for u in user_result.get("users", [])[:5]:
print(f"@{u.get('uniqueId'):<25} {u.get('follower_count',0):>8,} followers")JavaScript Example
const API_KEY = 'your-scavio-api-key';
async function searchVideos(query, cursor = 0, count = 20) {
const res = await fetch('https://api.scavio.dev/api/v1/tiktok/search/videos', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` },
body: JSON.stringify({ query, cursor, count })
});
if (!res.ok) throw new Error(`Failed: ${res.status}`);
return res.json();
}
async function searchUsers(query, cursor = 0) {
const res = await fetch('https://api.scavio.dev/api/v1/tiktok/search/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` },
body: JSON.stringify({ query, cursor })
});
return res.json();
}
const videoResult = await searchVideos('ai coding tutorial');
const top = (videoResult.videos ?? [])
.filter(v => (v.stats?.playCount ?? 0) >= 50000)
.sort((a, b) => (b.stats?.playCount ?? 0) - (a.stats?.playCount ?? 0));
for (const v of top.slice(0, 5)) {
console.log(`${v.stats?.playCount?.toLocaleString()} plays | @${v.author?.uniqueId} | ${v.desc?.slice(0, 60)}`);
}Expected Output
=== Top Videos for 'ai coding tutorial' ===
1. 2,847,392 plays | @aicodingpro | How I built a full app in 10 minutes with AI
2. 1,203,441 plays | @techwithtim | Claude vs ChatGPT for coding - honest review
3. 891,022 plays | @cursordev | Cursor AI just changed everything
=== Users matching 'ai developer' ===
@aidevtools 1,240,000 followers
@buildwithclaude 890,441 followers