Hi,
I tried SearchTimeline endpoint, and noticed the “cursor” API param and two TimelineTimelineCursor entries in the result. Could you give me a quick example of how to properly paginate?
For instance, searching the latest tweets based on a query, and page from the first (latest) page of tweets to the next page till the end of the query result? The documentation is not as clear as I had hoped.
Great work, and thanks for the help!
Join in the discussion - add comment below:
So would the following query (use both “since yesterday” and “Latest”, without "until: today) ensure getting the most recent tweets from yesterday to the present of today? Then I can just paginate via the bottom cursor till I consume the remaining query results?
{“rawQuery”:"(word1 OR word2) lang:en since:2024-03-07 -filter:replies)",“count”:10,“cursor”:"",“querySource”:“typed_query”,“product”:“Latest”,“includePromotedContent”:false}
Thanks again!
The search api can only filter by date range, not to the minute.
{“rawQuery”:“until:2024-03-07 since:2024-03-08 search something”,“count”:20,“querySource”:“typed_query”,“product”:“Latest”}
Yes, the top of the first page also has a value, and if you use the cursor in this top 1 minute later, the api will only return the new content, which is equivalent to flipping forward.
Also is it possible to filter time by hours/minutes instead of dates, such as new tweets within the last 10 minutes?
Thanks for the reply. Assuming the following query is used.
{“rawQuery”:"(word1 OR word2) lang:en since:2024-03-01 -filter:replies)",“count”:10,“cursor”:"",“querySource”:“typed_query”,“product”:“Latest”,“includePromotedContent”:false}
Please note the order of retrieval is “Latest” and “Since”, so I assume the tweets are returned in the order of post date, starting from the latest. So the correct pagination logic would be: make the first request, then keep paging with the Bottom cursor till the query result returns empty (end of query results)?
What’s confusing though is after the first request, the Top cursor (as you said for “previous page”) is also non-empty, and one can paginate through the Top cursor and get non-empty results back (which means the first query doesn’t return the most latest tweets?). Such behavior is different from a database cursor, and I am just trying to get a clear understanding of how to properly paginate though the query results so that I don’t end up with missing tweets or duplicate tweets (again this depends on the cursor behavior).
Thanks again for the clarifications!
https://img.onl/T0CXtV
There are two TimelineTimelineCursors in the api return
cursorType for Bottom is the cursor to pass to get the next page and cursorType for Top is the cursor to pass to get the previous page, value is the cursor parameter you need.