Fetch a TikTok user's recent posts including play count, like count, comment count, share count, and video description via Scavio API at $0.005/page of results. Uses max_cursor pagination for fetching beyond the first page.
Prerequisites
- Scavio API key
- Target user's sec_uid (from profile endpoint)
- Python 3.8+ or Node.js 18+
Walkthrough
Step 1: Get the user sec_uid
First call the profile endpoint to get the sec_uid needed for posts.
import requests, os
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
profile = requests.post('https://api.scavio.dev/api/v1/tiktok/profile',
headers=HEADERS, json={'username': 'target_user'}).json()
sec_uid = profile['data']['user']['sec_uid']Step 2: Fetch first page of posts
Call the user/posts endpoint with sec_user_id and count.
resp = requests.post('https://api.scavio.dev/api/v1/tiktok/user/posts',
headers=HEADERS,
json={'sec_user_id': sec_uid, 'count': 20})
data = resp.json()['data']
for video in data.get('videos', []):
print(f"{video['desc'][:50]} | {video['stats']['playCount']:,} plays")Step 3: Paginate with max_cursor
Use max_cursor from the response to fetch the next page.
if data.get('has_more'):
next_page = requests.post(
'https://api.scavio.dev/api/v1/tiktok/user/posts',
headers=HEADERS,
json={'sec_user_id': sec_uid, 'count': 20,
'max_cursor': data['max_cursor']})
page2 = next_page.json()['data']
print(f'Page 2: {len(page2.get("videos", []))} videos')Python Example
import requests, os
HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
'Content-Type': 'application/json'}
def get_all_posts(username, max_pages=5):
profile = requests.post('https://api.scavio.dev/api/v1/tiktok/profile',
headers=HEADERS, json={'username': username}).json()
sec_uid = profile['data']['user']['sec_uid']
videos = []
params = {'sec_user_id': sec_uid, 'count': 20}
for _ in range(max_pages):
resp = requests.post('https://api.scavio.dev/api/v1/tiktok/user/posts',
headers=HEADERS, json=params).json()['data']
videos.extend(resp.get('videos', []))
if not resp.get('has_more'):
break
params['max_cursor'] = resp['max_cursor']
return videos
videos = get_all_posts('target_user')
print(f'Fetched {len(videos)} videos')JavaScript Example
const H = {'Authorization': `Bearer ${process.env.SCAVIO_API_KEY}`, 'Content-Type': 'application/json'};
async function getPosts(username, maxPages = 5) {
const profile = await fetch('https://api.scavio.dev/api/v1/tiktok/profile', {
method: 'POST', headers: H, body: JSON.stringify({username})
}).then(r => r.json());
const secUid = profile.data.user.sec_uid;
const videos = [];
let params = {sec_user_id: secUid, count: 20};
for (let i = 0; i < maxPages; i++) {
const r = await fetch('https://api.scavio.dev/api/v1/tiktok/user/posts', {
method: 'POST', headers: H, body: JSON.stringify(params)
}).then(r => r.json());
videos.push(...(r.data.videos || []));
if (!r.data.has_more) break;
params.max_cursor = r.data.max_cursor;
}
return videos;
}
getPosts('target_user').then(v => console.log(`${v.length} videos`));Expected Output
Array of video objects with description, play count, like count, comment count, share count, and video metadata for each post.