Offset and limit parameter problems

Hello,

In my app, I am successfully getting API results for Live Streams, but I currently have three problems:

  1. When I make a request without parameters, my _total is always different from the length of my streams array. I have at most gotten 10 stream objects when making a call, while the total is always greater.

  2. When setting a limit, it seems to be disregarded.

  3. Setting an offset is also disregarded.

I figure that if I solve the first issue that it might resolve the second two.

Here is my ajax call:

     offset = 0
     var url = 'https://api.twitch.tv/kraken/search/streams?limit=4&q='
       searchInput +'&offset=' + offset;
          console.log("url", url)
          $.ajax({
             type: 'GET',
             url: url,
             headers: {'Client-ID': 'xxxxxx'},
             success: function(data) {
             console.log("data", data)
    }

searchInput is an input field that I get from the user.

Here is an example of what I am getting back: data > Object {_total: 450, _links: Object, streams: Array(9)}

If you would like to look further into what is going on, I have the app up on Codepen

Any help would be appreciated!

  1. This is correct. _total is how many streams are currently live for the given query. It gives you the limit for pagination.
  2. I’m not seeing this behavior. You can call the API in a browser like this: https://api.twitch.tv/kraken/search/streams?q=dota2&limit=3&client_id=2w3di133kf30i7r9ai8b0i39zke4g3
  3. I’m also not seeing this behavior. Again, you can call this in a browser: https://api.twitch.tv/kraken/search/streams?q=dota2&limit=3&offset=10&client_id=2w3di133kf30i7r9ai8b0i39zke4g3

The code that you’ve shared has lexical scoping problems that are likely biting you. In particular, you’re overwriting the offset and url variables in multiple places. E.g. your offset is starting at 0 and incrementing by 1 each time.

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