I thought it’d be interesting to write a script to keep track of my Twitter followers, and notify me if someone stops following me. There are several existing sites which can do this for you, but I’m a bit wary about signing into random sites with my Twitter account (some of them will spam messages to your feed), and I also wanted to dust off my PHP coding skills so here was a decent opportunity.

The Twitter API provides a method to retrieve your follower list – the URL for my follower list is:


You can specify the format of the list by changing the extension – I went for JSON, but you can also choose XML, RSS or Atom.

To begin with, as a one-off, I retrieved my follower list and stored it in a MySQL database. Then, I coded a script to do the following:

  • Retrieve the follower list stored in the MySQL database, and store in an array called $oldFollowers.
  • Retrieve the most recent follower list and store in an array called $newFollowers.
  • If there are any new followers, retrieve their username and screen name using the Twitter API.
  • Compare $oldFollowers and $newFollowers – if there is a follower in $oldFollowers that doesn’t appear in $newFollowers then that person no longer follows me.
  • If there are any people who no longer follow me, send an email alert.

I’ve added a cron job to run this once a day. So far there haven’t been any problems and it’s running smoothly.

Update 5th August 2011: I’ve created a repository on github with the script and some SQL to define the required table. I mentioned above about the script sending an email alert, but in reality all it does is echo a message saying ‘xxx is no longer following you’, which is then emailed to me as the output of the cron job.

Update 13th March 2013: I’ve just committed a fix to the script – it was broken by a Twitter API update last year but I’ve only just got around to updating the script on github. It should be working now!

8 thoughts on “Keeping track of my Twitter followers

  1. Hi!
    I just read your post (about followers) and some info. on Twitter’s website about visitors statistics. Is there any third party engine that gives info. about visitors (specially non-followers) in a Twitter account (info.: IP location, time spent on the account by the visitor, etc)? Or does the Twitter gives away this type of info to the account holders? To write a script for that purpose would be possible in your opinion?
    Please, reply me when you have time. THANKS.

    1. Hi, thanks for your comment! As far as I’m aware it’s impossible to keep track of which visitors are reading your Twitter feed, as readers could be using one of any number of clients (e.g Twitter website, TweetDeck desktop or mobile app, Echofon etc) and even if they do keep this information it isn’t accessible via the Twitter API. Hope this is useful for you.

  2. Hey Keane,

    Any thoughts on making this source code available, or open source? I’m looking at coding more or less exactly the same thing. Always looking for ways to prevent re-coding something that’s already been done well 🙂


  3. Hi Keane

    I have a task to complete and is to create a My Sql database to retrieve a list of followers for a particular user. I got some idea after looking at the above article but it would be grateful if you could advise me with it.Thnx.

      1. Hi Keane. Thanks a lot! In my case Its just to retrieve the followers list so I think its enough to do the first half bit of the coding like
        My Sql authentication details, replacing twitter ID with the my twitter user ID and get the current followers list using curl.

Leave a Reply

Your email address will not be published. Required fields are marked *