ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Build a TikTok Hashtag Tracker
Tutorial

How to Build a TikTok Hashtag Tracker

Track TikTok hashtag video_count and view_count daily using the Scavio TikTok API. Store data in SQLite and detect trending hashtags automatically.

Get Free API KeyAPI Docs

You can track TikTok hashtag growth by calling the Scavio TikTok hashtag endpoint daily, storing video_count and view_count in SQLite, and calculating day-over-day growth rates to surface trending tags.

Prerequisites

  • Python 3.9+
  • Scavio API key with TikTok access
  • SQLite (stdlib)

Walkthrough

Step 1: Fetch hashtag stats from the TikTok API

The TikTok hashtag endpoint returns current video count and view count for a hashtag.

Python
import requests

API_KEY = "your-scavio-api-key"

def get_hashtag_stats(hashtag: str) -> dict:
    # Remove # if present
    tag = hashtag.lstrip("#")
    r = requests.post(
        f"https://api.scavio.dev/api/v1/tiktok/hashtag",
        json={"hashtag": tag},
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=15
    )
    r.raise_for_status()
    return r.json()

stats = get_hashtag_stats("aitools")
print(stats)

Step 2: Store daily snapshots in SQLite

Save video_count and view_count for each hashtag each day.

Python
import sqlite3
from datetime import date

def init_db(path="hashtag_tracker.db"):
    conn = sqlite3.connect(path)
    conn.execute("""
        CREATE TABLE IF NOT EXISTS snapshots (
            date TEXT,
            hashtag TEXT,
            video_count INTEGER,
            view_count INTEGER,
            PRIMARY KEY (date, hashtag)
        )
    """)
    conn.commit()
    return conn

def save_snapshot(conn, hashtag: str, stats: dict):
    conn.execute(
        "INSERT OR REPLACE INTO snapshots VALUES (?, ?, ?, ?)",
        (
            str(date.today()),
            hashtag,
            stats.get("video_count", 0),
            stats.get("view_count", 0)
        )
    )
    conn.commit()

Step 3: Calculate day-over-day growth

Compare today's counts with yesterday's to find fastest-growing hashtags.

Python
def get_growth(conn, hashtag: str) -> dict:
    rows = conn.execute(
        "SELECT date, video_count, view_count FROM snapshots WHERE hashtag=? ORDER BY date DESC LIMIT 2",
        (hashtag,)
    ).fetchall()
    if len(rows) < 2:
        return {"hashtag": hashtag, "growth_pct": None}
    today_vids = rows[0][1]
    yesterday_vids = rows[1][1]
    if yesterday_vids == 0:
        return {"hashtag": hashtag, "growth_pct": None}
    growth = (today_vids - yesterday_vids) / yesterday_vids * 100
    return {
        "hashtag": hashtag,
        "today_videos": today_vids,
        "yesterday_videos": yesterday_vids,
        "growth_pct": round(growth, 2)
    }

Step 4: Run the daily tracking cron

Save this as track_hashtags.py and schedule with cron: 0 9 * * * python /path/to/track_hashtags.py

Python
HASHTAGS = ["aitools", "llm", "chatgpt", "claude", "openai", "cursor", "vibe coding"]

conn = init_db()
results = []

for tag in HASHTAGS:
    try:
        stats = get_hashtag_stats(tag)
        save_snapshot(conn, tag, stats)
        growth = get_growth(conn, tag)
        results.append(growth)
    except Exception as e:
        print(f"Error tracking #{tag}: {e}")

# Print trending hashtags (growth > 5%)
results.sort(key=lambda x: x.get("growth_pct") or 0, reverse=True)
print("\nTrending hashtags today:")
for r in results:
    if r.get("growth_pct") and r["growth_pct"] > 5:
        print(f"  #{r['hashtag']}: +{r['growth_pct']}% new videos")

Python Example

Python
import requests
import sqlite3
from datetime import date

API_KEY = "your-scavio-api-key"
HASHTAGS = ["aitools", "llm", "chatgpt", "claude", "openai", "cursor"]

def get_hashtag_stats(tag: str) -> dict:
    r = requests.post(
        "https://api.scavio.dev/api/v1/tiktok/hashtag",
        json={"hashtag": tag.lstrip("#")},
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=15
    )
    r.raise_for_status()
    return r.json()

def init_db(path="hashtag_tracker.db"):
    conn = sqlite3.connect(path)
    conn.execute("CREATE TABLE IF NOT EXISTS snapshots (date TEXT, hashtag TEXT, video_count INTEGER, view_count INTEGER, PRIMARY KEY (date, hashtag))")
    conn.commit()
    return conn

def save(conn, tag, stats):
    conn.execute("INSERT OR REPLACE INTO snapshots VALUES (?,?,?,?)",
                 (str(date.today()), tag, stats.get("video_count",0), stats.get("view_count",0)))
    conn.commit()

def growth(conn, tag):
    rows = conn.execute("SELECT video_count FROM snapshots WHERE hashtag=? ORDER BY date DESC LIMIT 2", (tag,)).fetchall()
    if len(rows) < 2 or rows[1][0] == 0:
        return None
    return round((rows[0][0] - rows[1][0]) / rows[1][0] * 100, 2)

if __name__ == "__main__":
    conn = init_db()
    print(f"TikTok Hashtag Report — {date.today()}")
    print("-" * 50)
    for tag in HASHTAGS:
        try:
            stats = get_hashtag_stats(tag)
            save(conn, tag, stats)
            g = growth(conn, tag)
            g_str = f"+{g}%" if g and g > 0 else (f"{g}%" if g else "no prior data")
            print(f"#{tag:<20} {stats.get('video_count',0):>12,} videos | growth: {g_str}")
        except Exception as e:
            print(f"#{tag}: error - {e}")

JavaScript Example

JavaScript
const API_KEY = 'your-scavio-api-key';
const HASHTAGS = ['aitools', 'llm', 'chatgpt', 'claude', 'cursor'];

async function getHashtagStats(tag) {
  const res = await fetch('https://api.scavio.dev/api/v1/tiktok/hashtag', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}` },
    body: JSON.stringify({ hashtag: tag.replace(/^#/, '') })
  });
  if (!res.ok) throw new Error(`Failed: ${res.status}`);
  return res.json();
}

for (const tag of HASHTAGS) {
  const stats = await getHashtagStats(tag);
  console.log(`#${tag}: ${stats.video_count?.toLocaleString()} videos, ${stats.view_count?.toLocaleString()} views`);
}

Expected Output

JSON
TikTok Hashtag Report - 2026-05-22
--------------------------------------------------
#aitools              1,247,832 videos | growth: +3.2%
#llm                    892,441 videos | growth: +8.7%
#chatgpt              4,102,991 videos | growth: +1.1%
#claude                 341,209 videos | growth: +12.4%
#openai               2,890,112 videos | growth: +0.8%
#cursor                 198,441 videos | growth: +15.2%

Related Tutorials

  • How to Search TikTok Videos and Users via API
  • How to Build a TikTok UGC Campaign Tracker
  • How to Build a TikTok Competitor Content Analyzer

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. SQLite (stdlib). 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

Best Of

Best TikTok Hashtag Analytics APIs (2026)

Read more
Use Case

TikTok Hashtag Campaign Monitoring

Read more
Workflow

TikTok Hashtag Campaign Tracker Workflow

Read more
Best Of

Best TikTok Hashtag Campaign Tracking Tools in May 2026

Read more
Glossary

TikTok Hashtag Analytics

Read more
Use Case

TikTok Hashtag Campaign Tracking

Read more

Start Building

Track TikTok hashtag video_count and view_count daily using the Scavio TikTok API. Store data in SQLite and detect trending hashtags automatically.

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