ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a TikTok Competitor Content Analyzer
Tutorial

How to Build a TikTok Competitor Content Analyzer

Analyze a competitor's TikTok content strategy by pulling their posts via API and calculating posting frequency, average engagement, and top content formats.

Get Free API KeyAPI Docs

You can analyze a competitor's TikTok content strategy by fetching their posts via the Scavio TikTok API using the two-step username-to-sec_uid flow, then computing posting frequency, engagement rates, and top-performing content patterns.

Prerequisites

  • Python 3.9+
  • Scavio API key with TikTok access

Walkthrough

Step 1: Get sec_uid from competitor username

Step 1: Resolve the username to sec_uid via the profile endpoint.

Python
import requests

API_KEY = "your-scavio-api-key"

def get_sec_uid(username: str) -> str:
    r = requests.post(
        "https://api.scavio.dev/api/v1/tiktok/user/profile",
        json={"username": username},
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=15
    )
    r.raise_for_status()
    return r.json().get("sec_uid")

Step 2: Fetch their recent posts

Step 2: Use sec_uid with max_cursor pagination to get up to 90 recent posts.

Python
def get_posts(sec_uid: str, max_count: int = 90) -> list:
    all_posts, cursor = [], 0
    while len(all_posts) < max_count:
        r = requests.post(
            "https://api.scavio.dev/api/v1/tiktok/user/posts",
            json={"sec_uid": sec_uid, "count": 30, "max_cursor": cursor},
            headers={"Authorization": f"Bearer {API_KEY}"},
            timeout=20
        )
        r.raise_for_status()
        data = r.json()
        batch = data.get("videos", [])
        if not batch: break
        all_posts.extend(batch)
        if not data.get("has_more"): break
        cursor = data.get("max_cursor", 0)
    return all_posts[:max_count]

Step 3: Analyze content patterns

Calculate posting frequency, average engagement, and identify top content formats.

Python
from collections import Counter

def analyze_posts(posts: list) -> dict:
    if not posts:
        return {}
    total = len(posts)
    plays = [p.get("stats",{}).get("playCount",0) for p in posts]
    likes = [p.get("stats",{}).get("diggCount",0) for p in posts]
    avg_plays = sum(plays) / total
    avg_likes = sum(likes) / total
    top_posts = sorted(posts, key=lambda p: p.get("stats",{}).get("playCount",0), reverse=True)[:5]
    descs = [p.get("desc","") for p in posts]
    # Detect hashtags used
    import re
    all_tags = [tag for desc in descs for tag in re.findall(r"#(\w+)", desc)]
    top_tags = Counter(all_tags).most_common(10)
    return {
        "total_posts": total,
        "avg_plays": round(avg_plays),
        "avg_likes": round(avg_likes),
        "top_hashtags": top_tags,
        "top_posts": [{"desc": p.get("desc","")[:80], "plays": p.get("stats",{}).get("playCount",0)} for p in top_posts]
    }

Python Example

Python
import requests
import re
from collections import Counter

API_KEY = "your-scavio-api-key"

def get_sec_uid(username):
    r = requests.post("https://api.scavio.dev/api/v1/tiktok/user/profile",
                      json={"username": username}, headers={"Authorization": f"Bearer {API_KEY}"}, timeout=15)
    r.raise_for_status()
    return r.json().get("sec_uid")

def get_posts(sec_uid, max_count=90):
    posts, cursor = [], 0
    while len(posts) < max_count:
        r = requests.post("https://api.scavio.dev/api/v1/tiktok/user/posts",
                          json={"sec_uid": sec_uid, "count": 30, "max_cursor": cursor},
                          headers={"Authorization": f"Bearer {API_KEY}"}, timeout=20)
        r.raise_for_status()
        data = r.json()
        batch = data.get("videos", [])
        if not batch: break
        posts.extend(batch)
        if not data.get("has_more"): break
        cursor = data.get("max_cursor", 0)
    return posts[:max_count]

def analyze(posts):
    if not posts: return {}
    plays = [p.get("stats",{}).get("playCount",0) for p in posts]
    likes = [p.get("stats",{}).get("diggCount",0) for p in posts]
    tags = Counter(t for p in posts for t in re.findall(r"#(\w+)", p.get("desc","")))
    top = sorted(posts, key=lambda p: p.get("stats",{}).get("playCount",0), reverse=True)[:3]
    return {"count": len(posts), "avg_plays": round(sum(plays)/len(plays)),
            "avg_likes": round(sum(likes)/len(likes)), "top_tags": tags.most_common(5),
            "top_posts": [{"desc": p.get("desc","")[:60], "plays": p.get("stats",{}).get("playCount",0)} for p in top]}

def analyze_competitor(username):
    print(f"Analyzing @{username}...")
    sec_uid = get_sec_uid(username)
    if not sec_uid: return print("Not found")
    posts = get_posts(sec_uid)
    stats = analyze(posts)
    print(f"Posts analyzed: {stats['count']}")
    print(f"Avg plays: {stats['avg_plays']:,} | Avg likes: {stats['avg_likes']:,}")
    print(f"Top hashtags: {[t[0] for t in stats['top_tags']]}")
    print("Top posts:")
    for p in stats["top_posts"]:
        print(f"  {p['plays']:>8,} plays | {p['desc']}")

if __name__ == "__main__":
    analyze_competitor("competitor_username")

JavaScript Example

JavaScript
const API_KEY = 'your-scavio-api-key';

async function getSecUid(username) {
  const res = await fetch('https://api.scavio.dev/api/v1/tiktok/user/profile', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` },
    body: JSON.stringify({ username })
  });
  return (await res.json()).sec_uid;
}

async function getPosts(secUid, count = 30) {
  const res = await fetch('https://api.scavio.dev/api/v1/tiktok/user/posts', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` },
    body: JSON.stringify({ sec_uid: secUid, count, max_cursor: 0 })
  });
  return (await res.json()).videos ?? [];
}

const secUid = await getSecUid('competitor_username');
const posts = await getPosts(secUid);
const avgPlays = posts.reduce((s, p) => s + (p.stats?.playCount ?? 0), 0) / posts.length;
console.log(`Avg plays: ${Math.round(avgPlays).toLocaleString()}`);

Expected Output

JSON
Analyzing @competitor_username...
Posts analyzed: 90
Avg plays: 482,441 | Avg likes: 38,209
Top hashtags: ['aitools', 'coding', 'tutorial', 'learntocode', 'python']
Top posts:
  2,841,209 plays | How I built this in 10 minutes using AI #aitools
  1,209,441 plays | Stop using ChatGPT for coding. Use this instead
    891,022 plays | The AI tool that replaced 3 apps for me #productivity

Related Tutorials

  • How to Build a TikTok Influencer Vetting Workflow
  • How to Build a TikTok UGC Campaign Tracker
  • How to Search TikTok Videos and Users via API

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.

Python 3.9+. Scavio API key with TikTok access. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, 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.

Related Resources

Use Case

TikTok Competitor Content Strategy Analysis

Read more
Solution

Analyze Competitor TikTok Content Strategy

Read more
Use Case

TikTok Content Optimization via API Data

Read more
Best Of

Best TikTok Hashtag Analytics APIs (2026)

Read more
Best Of

Best Search API for Content Research in 2026

Read more
Solution

TikTok Competitor Content Intelligence

Read more

Start Building

Analyze a competitor's TikTok content strategy by pulling their posts via API and calculating posting frequency, average engagement, and top content formats.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy