Great question! To fetch Number of Likes and Number of Followers from millions of Facebook pages submitted by users on wizbrand.com, you’ll need a scalable, permission-based data collection system. Since Facebook restricts these metrics to page owners/admins, here’s how you can make it work legally and effectively:
1. User Authorization and Permission Request
When a user submits their Facebook Page URL, you must:
- Request OAuth Authorization from the user via the Facebook Graph API.
- Ask for permissions like
pages_read_engagement
and pages_read_user_content
to access fan_count
and followers_count
.
Steps:
- Use Facebook Login on wizbrand.com to let users authenticate with their Facebook account.
- Once authenticated, the user grants permissions for wizbrand to access their Facebook page metrics.
Permissions Required:
pages_read_engagement
– Allows access to insights for pages the user manages.
pages_show_list
– To list pages the user manages.
2. Token Management
You will need to handle Access Tokens for each page:
- Generate a Page Access Token after the user grants permission.
- Store the Token securely in your database.
- Refresh Tokens periodically, as tokens can expire.
Example Token Request:
https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&fb_exchange_token=USER_ACCESS_TOKEN
3. Fetch Page Data Using Facebook Graph API
Once the token is in place, periodically fetch fan_count
and followers_count
for each page using the Graph API.
Example API Request:
https://graph.facebook.com/v17.0/{page_id}?fields=fan_count,followers_count&access_token={page_access_token}
4. Data Storage and Historical Tracking
Create a database schema to store and track historical data for each page:
| Field | Description |
|------------------|-----------------------------|
| page_id
| Facebook Page ID |
| page_name
| Name of the Facebook Page |
| fan_count
| Number of Likes |
| followers_count
| Number of Followers |
| timestamp
| When the data was collected |
Use a Cron Job or Scheduled Task to update this data daily or weekly for millions of pages.
5. Handle Rate Limits and API Quotas
Facebook enforces rate limits, so you must optimize requests:
- Batch API Requests for multiple pages in one call.
- Use Caching to reduce unnecessary requests.
- Monitor API usage and apply for higher-rate limits if needed.
Example Batch Request:
https://graph.facebook.com?ids={page_id_1},{page_id_2}&fields=fan_count,followers_count&access_token={access_token}
6. Legal Compliance and User Privacy
- Obtain User Consent: Clearly state why and how you’re collecting the data.
- Data Usage Policy: Align with Facebook Platform Terms and ensure data is only used for the stated purpose.
- Allow Users to Revoke Access: Give users an option to remove their data at any time.
7. Scalability Strategy
- Use Asynchronous Processing (e.g., AWS Lambda, Celery) to fetch and update data for millions of pages.
- Load Balancing and Queuing: Distribute requests to avoid server overload.
- Database Optimization: Use indexing and partitioning to handle large datasets.
Simplified Workflow:
- User submits Facebook page →
- OAuth Authentication & Permission →
- Generate Access Token →
- Fetch likes/followers using Graph API →
- Store in the database →
- Schedule periodic updates →
- Display historical data on wizbrand.com.
Alternative Options
If you want to bypass the need for user authentication, consider:
- Third-party APIs like Social Blade or similar services that offer aggregated social media data (but may have limitations).
- Crowdsourced data submission (users provide likes/followers manually, and you verify periodically).
Let me know if you want a sample PHP, Python, or Laravel code for this workflow, or if you want an API integration plan!