How to get follower count at time of tweet?



When I use tweet.user.followers_count, it gives me the CURRENT number of followers of the twitter handle corresponding to a tweet. How can I get the number of followers of that user at the time of the tweet itself?



If you have the tweet json from the stream, the embedded user object will have the counts at the time of the tweet - but if you request the tweet from the REST API again, you will get the current counts, and there’s no way to go back and request an older version of a user object.


So how do I get the tweet json? Can you give me a link or preferably some sample code please?


Depends on what library / language you’re using - but any good library will have some sort of listener you can use to store tweet messages - which contain the user object:

Here’s HBC in Java: that uses 2 listeners, but you only need 1 - implementing the onStatus event - you can get at the User object from that, and log counts (friends, followers) you’re interested in over time - these will be the counts as they were at the time the tweet was posted.


Any advice on how to do this using python / tweepy?


The basic example writes everything to stdout so you’ll need to write your own StreamListener and save statuses, and do all the counting etc using on_status events:


I have a stream listener with an on_status method as below, but am not clear on how to capture and save follower count of the user. Do I save it in some global data structure, such as a list?

def on_status(self, status):