Tutorial

How to Get TikTok User Posts via API

Fetch a TikTok user's recent videos with engagement data using Scavio API. Python and JavaScript examples with pagination.

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.

Python
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.

Python
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.

Python
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

Python
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

JavaScript
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

JSON
Array of video objects with description, play count, like count, comment count, share count, and video metadata for each post.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Scavio API key. Target user's sec_uid (from profile endpoint). Python 3.8+ or Node.js 18+. A Scavio API key gives you 250 free credits per month.

Yes. The free tier includes 250 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Fetch a TikTok user's recent videos with engagement data using Scavio API. Python and JavaScript examples with pagination.