Sort Stream by View Count

I would like to search through the streams by game, and find the streams with the lowest amount of views. This is what I have:

https://api.twitch.tv/kraken/streams/?sort=views&language=en&game=Overwatch&limit=5

But it doesn’t return the desired results. I’ve read the docs over and over and I don’t see a way to do this, even though the data has the number of views.

The docs don’t list sort as a querystring param for that endpoint, plus it’s already sorted by views anyway, just descending.

As they’re sorted by descending viewer count though, you could either just poll through all results and just reverse the array, or look at the _total field and use that to calculate what offset you need to get end of the results and work back from there.

Thanks for replying so quickly!

I’m a little confused about the offset. Offset is used for pagination right, so would that be the number of how many links for the pagination I would like? And Limit is the number of results I would liked displayed per page? / I’m confused how that would help me sort by view count by lowest amount of views.

I’ve tried pulling the request, getting the total amount of results, and then dividing the number by 100 (100 as the limit) but it’s not working. Could you point me in the right direction? Again, I’m just trying to grab the live streams by the lowest number of views.

Thanks again!

Offset is not the page, but rather how many entries your skipping. So if you perform a request without an offset and see the total is 1921, you could use an offset of 1821 to get the last 100 streams that the endpoint has, then 1721 if you want the next 100 and so on. That will get you the streams with the smallest viewer count, If you want to sort by any other metric then you’ll have to poll through all the results and sort them yourself.

Mind. Blown. Thank you so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.