Skip to main content


I couldn't find any implementation info on Twitter's API "cursoring" pagination system. I'd like to replicate it for #Friendica 's #API since we emulate their API, but so far I only have the "next_cursor" feature, no idea how to compute the "previous_cursor" value.

I'm looking for either a high-level explanation of this system that doesn't seem to rely on the usual "max_id"/'since_id" boundaries, or an actual implementation of it.

Thanks!

#help #webdev
Wouldn’t it be similar to a SQL cursor? An index into the result of a query?
@Brad Koehn ☑️ Probably, but I'm not sure how to implement that either in the context of stateless API calls. I don't want to hold the full result in memory not knowing if the cursor will soon be used backward. Going forward is simpler with the cursor parameter behaving like a since_id parameter to filter out previous results.
Well, all sql databases support queries with an index into the results. So the first page has an index of zero, then 10, 20, and so on. The next page increments the index by the count, and the previous page decrements it. You repeat the query for each request. That’s the most common implementation, though it has weaknesses, esp. around data inserts/deletes between requests.

Sorry if all this is obvious to you and you were thinking of something more sophisticated!
Never mind, the previous cursor value is negative, which allows to discriminate between since and max even with a single named parameter.

Thank you Brad for entertaining my question, I believe it was pivotal in my breakthrough.