To fetch data such as Number of Likes and Number of Followers from X (formerly Twitter) for thousands of submitted profiles without having access to their accounts, here’s a detailed guide:
Understanding the X API (formerly Twitter API):
Publicly Accessible Data: X allows public access to certain data via its Twitter API, but:
- You cannot fetch follower counts or engagement metrics without authentication.
- Public profile information (username, description, profile image, etc.) can be fetched without authorization.
Follower and Like Counts (Restricted Data):
You will need to use the X API v2 and obtain an OAuth Bearer Token from X. Unlike Facebook, Twitter allows fetching follower counts for public profiles without user-specific authorization, but you must be approved and use rate-limited API requests.
How to Fetch Follower and Like Data from X:
Step 1: Apply for X API Access
- Go to developer.twitter.com.
- Create a developer account and apply for Elevated Access to use the
User Lookup
and Tweet Metrics
endpoints.
Step 2: Obtain Bearer Token
Once approved, generate a Bearer Token to access the API.
https://api.twitter.com/oauth2/token
Step 3: Fetch Data using Twitter API v2
To fetch Number of Followers, Number of Likes, and other profile information, use the GET /users/by/username/:username
endpoint.
API Request:
GET https://api.twitter.com/2/users/by/username/{username}?user.fields=public_metrics
Authorization: Bearer YOUR_BEARER_TOKEN
Response Example:
{
"data": {
"id": "123456789",
"name": "John Doe",
"username": "johndoe",
"public_metrics": {
"followers_count": 5000,
"following_count": 200,
"tweet_count": 150,
"listed_count": 10
}
}
}
followers_count
: Number of followers.
following_count
: Number of users followed.
tweet_count
: Total number of tweets.
listed_count
: Number of times the account has been listed.
Step 4: Store Historical Data
- Create a database table to store the metrics for each X profile.
- Schedule a Cron Job to periodically update the data (e.g., every 24 hours).
- Use the data to display historical trends on wizbrand.com.
Database Schema Example:
| Field | Description |
|--------------------|-----------------------------|
| id
| Auto-incremented ID |
| x_username
| X profile username |
| followers_count
| Number of followers |
| likes_count
| Total likes (if tracked) |
| tweet_count
| Total tweets |
| timestamp
| Date and time of fetch |
Step 5: Handle API Rate Limits
X API has rate limits, so you must:
- Batch API Requests for multiple profiles.
- Use Caching to reduce repetitive requests.
- Distribute requests over time using a scheduling system (like Redis Queues or AWS Lambda).
Current Rate Limits (X API v2):
- User Lookup: 900 requests per 15-minute window (per App).
- Public Tweet Metrics: 1500 requests per 15-minute window (per App).
Challenges & Considerations:
- API Approval: Twitter’s new API policies have stricter requirements, and approval may take time.
- Rate Limits: Managing 10,000+ profiles will require an optimized request scheduling system.
- Privacy Compliance: Ensure compliance with Twitter’s API Terms—don’t expose private user data without consent.
- API Costs: X (Twitter) recently introduced paid API tiers for higher request volumes.
Alternative Solutions:
- Third-Party Services: Use tools like Social Blade for aggregated X data.
- Manual Submission with Verification: Allow users to submit and verify their follower/like counts manually.
Conclusion:
To implement this feature, your best option is to use the X API v2 with an OAuth Bearer Token to fetch and update public metrics for each submitted profile. Let me know if you want sample code in PHP, Python, or Laravel, and I’ll provide a working example!