Overview
TikTok Miner’s Twitter (X) integration uses Apify’s Twitter scraper to collect profile information, tweet metrics, and engagement data from public Twitter accounts. This integration provides access to Twitter data without requiring official API keys.How It Works
The Twitter integration operates through theActorManager class:
- Profile Scraping: Collects user information, follower counts, and bio data
- Tweet Analysis: Retrieves recent tweets with likes, retweets, and replies
- Engagement Metrics: Calculates average engagement rates and reach
- Data Transformation: Converts raw Twitter data into unified format
Architecture
- Actor Manager:
lib/apify/actor-manager.ts - Transformers:
lib/apify/transformers.ts - Configuration:
lib/apify/config.ts - Database Schema:
prisma/schema.prisma(TwitterMetrics model)
Configuration
Environment Variables
Service Setup
Data Collection
Profile Metrics
TheTwitterMetrics table stores:
| Field | Type | Description |
|---|---|---|
userId | String | Twitter user ID (unique) |
username | String | Twitter handle (unique) |
displayName | String | Display name |
followerCount | Int | Total followers |
followingCount | Int | Total following |
tweetCount | Int | Total tweets posted |
listedCount | Int | Number of lists user appears on |
averageLikes | Float | Average likes per tweet |
averageRetweets | Float | Average retweets per tweet |
averageReplies | Float | Average replies per tweet |
engagementRate | Float | Calculated engagement rate (%) |
isVerified | Boolean | Blue/gold checkmark status |
joinedAt | DateTime | Account creation date |
impressions | Int | Tweet impressions (if available) |
profileViews | Int | Profile views (if available) |
Data Model
Usage Examples
- Scrape Profile
- Calculate Engagement
- Analyze Tweets
- Store in Database
Rate Limits & Quotas
Apify Limits
- Free Tier: $5 in free credits monthly
- Personal Plan: Starting at $49/month
- Default Timeout: 300 seconds per run
- Memory: 512 MB default
- Concurrent Runs: Based on subscription tier
Twitter Scraper Configuration
Cost Optimization
Error Handling
Data Validation
TheTwitterTransformer ensures data quality:
- Username sanitization (removes @)
- Bio HTML/emoji stripping
- URL normalization
- Date parsing and validation
- Numeric type coercion
Advanced Features
Search Tweets
Monitor Engagement Over Time
Monitoring
Track Data Quality
Set Up Alerts
Best Practices
Limitations
- Protected Accounts: Cannot scrape tweets from protected accounts
- Rate Limits: Twitter may block excessive scraping attempts
- Deleted Tweets: Cannot access deleted or unavailable tweets
- Analytics Data: Impressions and profile views require Twitter API
- Real-time Updates: Slight delay compared to official API
- Media Content: High-resolution media may not be available
Troubleshooting
Common Issues
| Issue | Solution |
|---|---|
| ”Profile not found” | User may be suspended, deleted, or handle is incorrect |
| ”Rate limit exceeded” | Wait and retry with exponential backoff |
| ”Timeout error” | Increase timeoutSecs or reduce tweetsDesired |
| ”Invalid data format” | Twitter may have changed their HTML structure |