Tutorial

How to Build Public Account Analytics via TikTok API

Analyze any public TikTok account: engagement rate, posting frequency, and audience indicators. Python pipeline at $0.005/call.

You do not need to be an account owner to analyze public TikTok metrics. The Scavio TikTok API lets you pull any public profile and their recent posts to calculate engagement rates, posting frequency, audience growth indicators, and content performance patterns. Each call costs $0.005, making a full account audit under $0.02.

Prerequisites

  • Python 3.8+
  • requests library
  • A Scavio API key from scavio.dev
  • Target TikTok usernames to analyze

Walkthrough

Step 1: Fetch public profile data

Pull profile metrics for any public TikTok account.

Python
import os, requests, json
from datetime import datetime

API_KEY = os.environ['SCAVIO_API_KEY']
TH = {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}

def get_profile(username):
    data = requests.post('https://api.scavio.dev/api/v1/tiktok/profile',
        headers=TH, json={'username': username}).json()
    user = data.get('user', data.get('data', {}).get('user', data))
    return {
        'username': username,
        'followers': user.get('followerCount', user.get('fans', 0)),
        'following': user.get('followingCount', 0),
        'likes': user.get('heartCount', user.get('heart', 0)),
        'videos': user.get('videoCount', 0),
        'verified': user.get('verified', False),
        'bio': user.get('signature', '')[:100],
        'sec_uid': user.get('secUid', '')
    }

profile = get_profile('charlidamelio')
for k, v in profile.items():
    if k != 'sec_uid':
        val = f'{v:,}' if isinstance(v, int) else v
        print(f'  {k}: {val}')

Step 2: Analyze recent post performance

Fetch recent posts and calculate engagement metrics.

Python
def get_posts(sec_uid):
    data = requests.post('https://api.scavio.dev/api/v1/tiktok/user/posts',
        headers=TH, json={'sec_user_id': sec_uid}).json()
    posts = data.get('videos', data.get('data', {}).get('videos', []))
    return [{'desc': p.get('desc', '')[:60],
             'plays': p.get('stats', {}).get('playCount', 0),
             'likes': p.get('stats', {}).get('diggCount', 0),
             'comments': p.get('stats', {}).get('commentCount', 0),
             'shares': p.get('stats', {}).get('shareCount', 0),
             'created': p.get('createTime', 0)} for p in posts]

def analyze_engagement(posts, followers):
    if not posts or not followers:
        return {}
    total_eng = sum(p['likes'] + p['comments'] + p['shares'] for p in posts)
    total_plays = sum(p['plays'] for p in posts)
    avg_plays = total_plays / len(posts)
    avg_likes = sum(p['likes'] for p in posts) / len(posts)
    er = total_eng / total_plays * 100 if total_plays else 0
    follower_er = total_eng / (followers * len(posts)) * 100
    return {
        'avg_plays': int(avg_plays), 'avg_likes': int(avg_likes),
        'engagement_rate': round(er, 2), 'follower_er': round(follower_er, 2),
        'total_posts_analyzed': len(posts)
    }

posts = get_posts(profile['sec_uid'])
metrics = analyze_engagement(posts, profile['followers'])
for k, v in metrics.items():
    print(f'  {k}: {v:,}' if isinstance(v, int) else f'  {k}: {v}')

Step 3: Calculate posting frequency and patterns

Determine how often the account posts and identify timing patterns.

Python
from datetime import datetime

def posting_patterns(posts):
    if len(posts) < 2:
        return {}
    timestamps = sorted([p['created'] for p in posts if p['created']])
    if not timestamps:
        return {}
    # Calculate posting frequency
    time_span_days = (timestamps[-1] - timestamps[0]) / 86400 if len(timestamps) > 1 else 1
    freq = len(posts) / max(time_span_days, 1)
    # Day of week distribution
    days = [datetime.fromtimestamp(t).strftime('%A') for t in timestamps if t]
    day_counts = {}
    for d in days:
        day_counts[d] = day_counts.get(d, 0) + 1
    best_day = max(day_counts, key=day_counts.get) if day_counts else 'Unknown'
    return {
        'posts_per_day': round(freq, 2),
        'posts_per_week': round(freq * 7, 1),
        'most_active_day': best_day,
        'time_span_days': round(time_span_days, 0)
    }

patterns = posting_patterns(posts)
print('Posting patterns:')
for k, v in patterns.items():
    print(f'  {k}: {v}')

Step 4: Generate full account audit report

Combine all analytics into a comprehensive account report.

Python
def audit_account(username):
    print(f'\n=== TikTok Account Audit: @{username} ===')
    profile = get_profile(username)
    cost = 0.005
    print(f'\nProfile:')
    print(f'  Followers: {profile["followers"]:,} | Following: {profile["following"]:,}')
    print(f'  Total likes: {profile["likes"]:,} | Videos: {profile["videos"]}')
    print(f'  Verified: {profile["verified"]} | Bio: {profile["bio"][:50]}')
    posts = get_posts(profile['sec_uid'])
    cost += 0.005
    metrics = analyze_engagement(posts, profile['followers'])
    print(f'\nEngagement ({len(posts)} recent posts):')
    print(f'  Avg plays: {metrics.get("avg_plays", 0):,}')
    print(f'  Avg likes: {metrics.get("avg_likes", 0):,}')
    print(f'  Play-based ER: {metrics.get("engagement_rate", 0)}%')
    print(f'  Follower-based ER: {metrics.get("follower_er", 0)}%')
    patterns = posting_patterns(posts)
    print(f'\nPosting:')
    print(f'  Frequency: {patterns.get("posts_per_week", 0)} posts/week')
    print(f'  Most active: {patterns.get("most_active_day", "Unknown")}')
    # Top performing post
    if posts:
        top = max(posts, key=lambda p: p['plays'])
        print(f'\nTop post: {top["desc"][:50]}... ({top["plays"]:,} plays)')
    print(f'\nAudit cost: ${cost:.3f}')

audit_account('charlidamelio')

Python Example

Python
import os, requests
TH = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}', 'Content-Type': 'application/json'}

def audit(username):
    p = requests.post('https://api.scavio.dev/api/v1/tiktok/profile',
        headers=TH, json={'username': username}).json()
    user = p.get('user', p.get('data', {}).get('user', p))
    followers = user.get('followerCount', 0)
    posts_data = requests.post('https://api.scavio.dev/api/v1/tiktok/user/posts',
        headers=TH, json={'sec_user_id': user.get('secUid', '')}).json()
    vids = posts_data.get('videos', posts_data.get('data', {}).get('videos', []))[:10]
    total_likes = sum(v.get('stats', {}).get('diggCount', 0) for v in vids)
    total_plays = sum(v.get('stats', {}).get('playCount', 0) for v in vids)
    er = total_likes / total_plays * 100 if total_plays else 0
    print(f'@{username}: {followers:,} followers, {er:.2f}% ER, {len(vids)} posts. Cost: $0.010')

audit('charlidamelio')

JavaScript Example

JavaScript
const TH = { 'Authorization': `Bearer ${process.env.SCAVIO_API_KEY}`, 'Content-Type': 'application/json' };
async function audit(username) {
  const p = await fetch('https://api.scavio.dev/api/v1/tiktok/profile', {
    method: 'POST', headers: TH, body: JSON.stringify({ username })
  }).then(r => r.json());
  const user = p.user || p.data?.user || p;
  const posts = await fetch('https://api.scavio.dev/api/v1/tiktok/user/posts', {
    method: 'POST', headers: TH, body: JSON.stringify({ sec_user_id: user.secUid })
  }).then(r => r.json());
  const vids = (posts.videos || posts.data?.videos || []).slice(0, 10);
  const plays = vids.reduce((s, v) => s + (v.stats?.playCount || 0), 0);
  const likes = vids.reduce((s, v) => s + (v.stats?.diggCount || 0), 0);
  console.log(`@${username}: ${(user.followerCount||0).toLocaleString()} followers, ${(likes/plays*100).toFixed(2)}% ER`);
}
audit('charlidamelio').catch(console.error);

Expected Output

JSON
=== TikTok Account Audit: @charlidamelio ===

Profile:
  Followers: 155,200,000 | Following: 1,234
  Total likes: 11,800,000,000 | Videos: 2,456
  Verified: True | Bio: dance + vibes

Engagement (10 recent posts):
  Avg plays: 8,900,000
  Avg likes: 1,200,000
  Play-based ER: 14.52%
  Follower-based ER: 0.85%

Posting:
  Frequency: 4.2 posts/week
  Most active: Tuesday

Top post: New dance challenge with... (23,400,000 plays)

Audit cost: $0.010

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.

Python 3.8+. requests library. A Scavio API key from scavio.dev. Target TikTok usernames to analyze. 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

Analyze any public TikTok account: engagement rate, posting frequency, and audience indicators. Python pipeline at $0.005/call.