Hi, I’m new to the api and testing the functionality. How can I do a request with a reverse sort for example
https://api.twitch.tv/kraken/streams?&sort=views&language=en&game=overwatch
I don’t think there is a reverse direction for /streams
. You’ll probably have to use ._total
for &offset=
and &limit=
parameters.
/streams?sort=views&language=en&game=overwatch&limit=1
{ _total: 915, streams: [ {} ] }
Get all, in reverse chunks
You could use floor(_total / 100) * 100
to get the start offset for reverse sorting and use as many request as you need. You’ll still need to reverse the streams
array data.
/streams?sort=views&language=en&game=overwatch&offset=900&limit=100
// 15 items
/streams?sort=views&language=en&game=overwatch&offset=800&limit=100
// 100 items
....
/streams?sort=views&language=en&game=overwatch&offset=100&limit=100
// 100 items
/streams?sort=views&language=en&game=overwatch&offset=0&limit=100
// 100 items
Get the last 100
Or just subtract 100
from _total
and then go from there if you just want the last 100. Again, make sure to reverse the streams array data or at least recognize that it’s still descending order.
/streams?sort=views&language=en&game=overwatch&offset=815&limit=100
// 100 items
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.