[Solved] Uncaught TypeError: Cannot read property 'length' of undefined

That’s it I fixed it by myself! For me headers doesn’t work, so i put my token into the URL, just like that:

var api_kraken_streams = 'https://api.twitch.tv/kraken/streams/?client_id=xxx&limit=100&channel='

Here’s my code without HTML inserts:

var displayMax = 5;
      var streamers = ['TimTheTatman']; // Twitch API says channel names are case-sensitive, but I cannot confirm that.
     var api_kraken_streams = 'https://api.twitch.tv/kraken/streams/?client_id=xxx&limit=100&channel='; // returned object only contains streams that are live/online
      function reload() {
          url: api_kraken_streams + streamers.join(','),
          dataType: 'jsonp',
          type: 'get',
          success: function(data) {
            var divs = [];
            var online = [];
            // create new DIVs for online streams
            for (var i = 0, len = data.streams.length; i < len; i++) {
               var stream = data.streams[i];
              var nameLC = stream.channel.name.toLowerCase();
                var logo = stream.channel.logo;
                if (stream.game === 'Overwatch') {
              var div = jQuery(' \ Here goes some HTML-code');
            // replace old DIVs
            $('#streamers div').remove();
              $('#streamers span').remove();
              $('#streamers li').remove();
            for (var i = 0, len = divs.length; i < len; i++) {
              if (i < displayMax) {
      $(document).ready(function() {
        window.setInterval('reload();', 15 * 1000);

Jsonp uses a script tag to make the request (i.e. jQuery adds a <script src="your_url"></script> on the page), so you can’t specify headers for it. If you use dataType: 'json' instead, you can specify the header.

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