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

旧城冷巷雨未停 提交于 2019-12-20 08:49:32

问题


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..


回答1:


since_id and max_id are both very simple parameters you can use to limit what you get back from the API. From the docs:

since_id - Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available. max_id - Returns results with an ID less than (that is, older than) or equal to the specified ID.

So, if you have a given tweet ID, you can search for older or newer tweets by using these two parameters.

count is even simpler -- it specifies a maximum number of tweets you want to get back, up to 200.

Unfortunately the API will not give you back exactly what you want -- you cannot specify a date/time when querying user_timeline -- although you can specify one when using the search API. Anyway, if you need to use user_timeline, then you will need to poll the API, gathering up tweets, figuring out if they match the parameters you desire, and then calculating your stats accordingly.




回答2:


The max_id = top of tweets id list . since_id = bottom of tweets id list .

for more : get a deep look in the last diagram .. here




回答3:


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.

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.



来源:https://stackoverflow.com/questions/6412188/what-exactly-does-since-id-and-max-id-mean-in-the-twitter-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!