DEV Community

Xproapi
Xproapi

Posted on

How to Track X (Twitter) Follower Growth Using an API

How to Track X (Twitter) Follower Growth Using an API

Tracking follower growth is useful for more than just checking whether an account is gaining popularity.

For developers, marketers and creator management agencies, follower growth data can help measure campaign performance, monitor audience development, compare creator accounts and build social media analytics dashboards.

But manually checking follower counts across multiple accounts quickly becomes inefficient.

A better approach is to use an API to collect account information periodically, store historical snapshots and calculate growth over time.

In this guide, we'll explore how to build a simple X (formerly Twitter) follower growth tracker using a REST API and Python.

1. Understanding follower growth tracking

A follower growth tracker periodically retrieves an account's follower count and stores the result.

For example:

Date Followers
November 1 12,400
November 5 12,650
November 10 12,890
November 12 13,050

With historical data, you can calculate:

  • Total follower growth.
  • Daily follower growth.
  • Weekly and monthly growth.
  • Percentage growth.
  • Growth trends across multiple accounts.

The important part is not simply retrieving the current follower count. It's maintaining historical records so you can compare changes over time.

2. Retrieve account information through an API

Start by choosing an API provider that supports retrieving public X account information.

For this example, we'll use Python's Requests library.

Install it:

pip install requests python-dotenv
Enter fullscreen mode Exit fullscreen mode

Create a .env file:

XPROAPI_KEY=YOUR_API_KEY
Enter fullscreen mode Exit fullscreen mode

Load your API credentials:

import os
import requests

from dotenv import load_dotenv

load_dotenv()

API_KEY = os.getenv("XPROAPI_KEY")

BASE_URL = "https://xproapi.com/api"
Enter fullscreen mode Exit fullscreen mode

Next, create a function to retrieve account information.

The exact endpoint and response fields should follow the current XProAPI documentation:

def get_user_info(username):

    response = requests.get(
        f"{BASE_URL}/twitter/user/info",
        headers={
            "X-API-Key": API_KEY
        },
        params={
            "userName": username
        },
        timeout=(3, 15)
    )

    response.raise_for_status()

    return response.json()
Enter fullscreen mode Exit fullscreen mode

This function retrieves the account information for the requested username.

Important: Adapt the response parsing to the actual JSON structure returned by the endpoint. Never assume that a field exists without checking the API response.

3. Extract the follower count

Once you receive the response, identify the account identifier, username and follower count.

For example, suppose your API response contains:

{
    "id": "123456789",
    "username": "example_creator",
    "followers_count": 13050
}
Enter fullscreen mode Exit fullscreen mode

You can extract the values:

user_data = get_user_info("example_creator")

user_id = user_data["id"]
username = user_data["username"]
followers = user_data["followers_count"]

print(f"Username: {username}")
print(f"Followers: {followers}")
Enter fullscreen mode Exit fullscreen mode

This is an illustrative response structure. Adjust the field names and response nesting to match your actual API response.

4. Store historical follower counts

A single API request only tells you the current follower count.

To calculate growth, you need to save historical snapshots.

For a small application, SQLite is sufficient.

import sqlite3

connection = sqlite3.connect("follower_tracker.db")

connection.execute("""
CREATE TABLE IF NOT EXISTS follower_snapshots (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id TEXT NOT NULL,
    username TEXT NOT NULL,
    followers INTEGER NOT NULL,
    recorded_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
""")

connection.commit()
Enter fullscreen mode Exit fullscreen mode

Create a function to save each snapshot:

def save_snapshot(user_id, username, followers):

    connection.execute("""
        INSERT INTO follower_snapshots
        (user_id, username, followers)
        VALUES (?, ?, ?)
    """, (user_id, username, followers))

    connection.commit()
Enter fullscreen mode Exit fullscreen mode

Now, every time you retrieve an account's follower count, you can store a new historical record.

For larger applications, consider PostgreSQL or MySQL with an appropriate index on user_id and recorded_at.

5. Calculate follower growth

Once historical snapshots are available, calculating follower growth becomes straightforward.

For example:

def calculate_growth(previous, current):

    growth = current - previous

    if previous > 0:
        percentage = (growth / previous) * 100
    else:
        percentage = 0

    return {
        "growth": growth,
        "percentage": round(percentage, 2)
    }
Enter fullscreen mode Exit fullscreen mode

Example:

result = calculate_growth(
    previous=12400,
    current=13050
)

print(result)
Enter fullscreen mode Exit fullscreen mode

Output:

{
    "growth": 650,
    "percentage": 5.24
}
Enter fullscreen mode Exit fullscreen mode

This gives you two useful metrics:

  • Absolute growth: 650 additional followers.
  • Percentage growth: 5.24%.

You can use these metrics to build reports, dashboards and creator performance summaries.

6. Automate follower tracking

Manually running the script isn't practical when monitoring multiple accounts.

You can schedule the tracking process using:

  • Linux cron jobs.
  • Python APScheduler.
  • Celery with Redis.
  • Cloud scheduled jobs.
  • Your application's existing queue system.

For example, a cron job can execute your tracking script every six hours:

0 */6 * * * /usr/bin/python3 /app/track_followers.py
Enter fullscreen mode Exit fullscreen mode

Before increasing the frequency, consider your API plan, endpoint rate limits and credit consumption.

You should also prevent overlapping jobs and avoid creating duplicate snapshots when a previous collection is still running.

7. Monitor multiple creator accounts

For agencies managing multiple creators, the same system can be extended to track several accounts.

Create a list of accounts:

creators = [
    "creator_one",
    "creator_two",
    "creator_three",
    "creator_four"
]

for username in creators:

    try:
        user_data = get_user_info(username)

        # Map the actual API response fields here.
        # Save the account's latest follower snapshot.

        print(f"Successfully checked {username}")

    except requests.exceptions.RequestException as error:
        print(f"Failed to retrieve {username}: {error}")
Enter fullscreen mode Exit fullscreen mode

For production systems, consider:

  • Processing accounts in controlled batches.
  • Respecting rate limits.
  • Logging failed requests.
  • Retrying eligible temporary failures.
  • Tracking the last successful collection time.
  • Avoiding duplicate account records.

This approach makes it easier to monitor a large creator roster without manually checking each account.

8. Build alerts for significant growth changes

Historical follower data becomes even more useful when combined with notifications.

For example, you could trigger an alert when an account gains more than 500 followers within 24 hours.

A simplified comparison:

def should_send_alert(previous, current, threshold=500):

    growth = current - previous

    return growth >= threshold
Enter fullscreen mode Exit fullscreen mode

Your application can then send notifications through:

  • Email.
  • Discord.
  • Slack.
  • Telegram.
  • Internal dashboards.

For more advanced systems, calculate growth over rolling time windows and account for missing snapshots, delayed data and collection failures.

Remember that follower count changes alone do not explain why an account gained or lost followers.

9. Important considerations when building a follower tracker

Before deploying a monitoring system, consider the following:

Data freshness: A retrieved follower count represents the data returned at collection time. It is not necessarily a continuously updated real-time measurement.

API limits: Schedule requests according to your API plan and applicable rate limits.

Historical accuracy: Store timestamps with every snapshot. Avoid treating a missing collection as zero followers.

Account identification: Use stable account identifiers rather than relying exclusively on usernames, which can change.

Data retention: Decide how long historical snapshots should be retained and provide appropriate data handling controls.

Platform policies: Ensure your collection and use of public account data comply with applicable platform policies and your API provider's terms.

Conclusion

Building an X follower growth tracker doesn't require a complicated analytics platform.

With a REST API, a small database and a scheduled collection process, you can create a system that tracks historical follower counts, calculates growth and sends alerts when significant changes occur.

The same foundation can support creator management platforms, marketing analytics applications, social media reporting tools and multi-account monitoring systems.

Explore XProAPI

If you're developing applications that work with X (formerly Twitter) data, XProAPI provides developer-focused REST APIs for accessing supported public account and content information.

Use API integrations to build your own account analytics, follower tracking and social data applications.

Start building your own social data applications with XProAPI.

Top comments (0)