How to get follower count at time of tweet?

fabric
oauth
user
streaming
tweepy

#1

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?

Thanks,
Haris


#2

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.


#3

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


#4

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: https://dev.twitter.com/streaming/overview/messages-types#public_stream_messages

Here’s HBC in Java: https://github.com/twitter/hbc/blob/master/hbc-example/src/main/java/com/twitter/hbc/example/Twitter4jSampleStreamExample.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.


#5

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


#6

The basic example writes everything to stdout https://github.com/tweepy/tweepy/blob/master/examples/streaming.py so you’ll need to write your own StreamListener and save statuses, and do all the counting etc using on_status events: http://docs.tweepy.org/en/v3.5.0/streaming_how_to.html#step-1-creating-a-streamlistener


#7

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):
    print(user.status.follower_count)
    print(status.text)

#8

Did you ever find the answer to this?
I am getting the tweet json and it does have an embedded user object as IgorBrigadir mentions, but all of each tweet brings the current user information rather than the information when the tweet was submitted.

I’m using the lists/statuses call:
https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses


#9

I suggest that you use one of our realtime, streaming APIs.

I also suggest that you keep an eye on our roadmap.