Overview
TikTok Miner uses the Apify TikTok scraper to collect profile data, engagement metrics, and video content from TikTok. This integration provides a powerful alternative to the official TikTok API, which has limited availability for third-party developers.How It Works
The TikTok integration operates through theTikTokApifyService class, which orchestrates:
- Profile Scraping: Collects user profile information, follower counts, and verification status
- Video Data: Retrieves recent videos with engagement metrics (likes, comments, shares, views)
- Search Capabilities: Discovers creators by keywords and hashtags
- Data Transformation: Converts raw Apify data into unified TikTok Miner format
Architecture
- Service:
lib/services/tiktok-apify-service.ts - Actor Manager:
lib/apify/actor-manager.ts - Transformers:
lib/apify/transformers.ts - Database Schema:
prisma/schema.prisma(TiktokMetrics model)
Configuration
Required Environment Variables
Service Initialization
Data Collection
Profile Metrics
The TikTok integration collects the following metrics stored in theTiktokMetrics table:
| Field | Type | Description |
|---|---|---|
followerCount | Int | Total number of followers |
followingCount | Int | Total number of accounts followed |
videoCount | Int | Total number of videos posted |
heartCount | BigInt | Total likes across all videos |
averageViews | Int | Average views per video |
averageLikes | Int | Average likes per video |
averageComments | Int | Average comments per video |
averageShares | Int | Average shares per video |
engagementRate | Float | Calculated engagement rate (%) |
totalViews | BigInt | Cumulative views across all content |
dailyViewGrowth | Float | Daily view growth rate (optional) |
dailyFollowerGrowth | Float | Daily follower growth rate (optional) |
Profile Data Model
Usage Examples
- Fetch User Profile
- Get Video Insights
- Search Creators
- Store in Database
Rate Limits & Quotas
Apify Rate Limits
The TikTok scraper runs on Apify’s infrastructure with the following considerations:- Concurrent Runs: Limited by your Apify subscription tier
- Compute Units: Charges apply per actor run based on execution time and memory
- Default Timeout: 300 seconds (5 minutes) per run
- Memory Allocation: 512 MB by default (configurable)
Cost Management
Best Practices
Error Handling
Data Quality
TheTiktokTransformer class ensures data quality through:
- Sanitization: Usernames, bios, and URLs are cleaned
- Validation: Data is validated against Zod schemas
- Normalization: Metrics are normalized to consistent types
- Fallbacks: Default values prevent null pointer errors
Monitoring & Alerts
Track your TikTok scraping performance:Limitations
TikTok Scraper Limitations:
- No access to private account data
- Video insights are limited to publicly available metrics
- OAuth flow is not supported (scraping-based approach)
- Real-time data may have a slight delay
- Detailed analytics require TikTok Business API (not included)