What exactly does 'since_id' and 'max_id' mean in the Twitter API

Viewed 36500

I've been poring over the Twitter docs for some time now, and I've hit a wall how to get stats for growth of followers over a period of time / count of tweets over a period of time...

I want to understand from the community what does since_id and max_id and count mean in the Twitter API.

I've been following this page https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline

I'm trying to get stats for a user --

  • counts of tweets in a particular time period
  • count of followers over a particular time period
  • count of retweets

I'd like some help forming querystrings for the above..

Thanks..

3 Answers

The max_id and since_id are used to prevent redundancy in the case of Twitter API calls. Visualize the tweets coming in as piling onto a stack. One API call has to specify how many (count) tweets will be processed. But as this call is made, new tweets may be added. In that case, if you draw out a stack and run through the process, you notice that there can be some 'fragmentation' or sections of unprocessed tweets stuck in between processed ones. This is visible in below image as well.

enter image description here

To get around this problem, two parameters are used to keep track of the latest/greatest ID tweet previously processed (since_id) and the oldest/lowest ID tweet recently processed (max_id). The since_id points to the bottom of the 'fragment' and the (max_id-1) points to the top of the 'fragment'. (Note that the max_id is inclusive unlike the since_id) So, the parameters together keep track of which part of the tweet stack still needs to be processed.

Related