title: Javascript external API calls with variable URL in for loop
body: <p>I am trying to call the Twitch API in a <code>for</code> loop where the URL being called changes with each iteration through the loop and the URL that gets called is actually one that was returned in the previous call.</p>
  
  <p>Why? - The Twitch API response limits you to 100 returned streams but includes a "next" link that sets the offset so that you can get the next 100 and then the next and so on.</p>
  
  <p>I am using meteor and wrote this:</p>
  
  <pre><code>var extractGames = function(limit, pages) {
      var gamesURL = 'https://api.twitch.tv/kraken/streams';
      for (i=0; i &lt; 3; i +=1) {
          Meteor.http.get(gamesURL, {
                  params: {
                      limit: limit,
                      api_version: 3
                  }
              }, function (err, res) {
                  if (err) {
                      console.log(res.message);
                      console.log(res.error);
                  } else {
                      gamesURL = res.data._links.next;
                      var data = res.data.streams;
                      console.log(gamesURL);
                      console.log(data[0].game);
                      console.log(data[75].game);
                      console.log("-----------");
                  }
  
              }
          )
      }
  };
  </code></pre>
  
  <p>I believe the problem is that the new URL is not getting called each time and rather the connection to the original is staying open and not changing. </p>
  
  <p>The response looks like this:</p>
  
  <pre><code>? https://api.twitch.tv/kraken/streams?limit=100&amp;offset=100
  ? H1Z1
  ? Pokémon Red/Blue
  ? -----------
  ? https://api.twitch.tv/kraken/streams?limit=100&amp;offset=100
  ? H1Z1
  ? Pokémon Red/Blue
  ? -----------
  ? https://api.twitch.tv/kraken/streams?limit=100&amp;offset=100
  ? H1Z1
  ? Pokémon Red/Blue
  ? -----------
  </code></pre>
  
  <p>How do I get the loop to call the new URL each time through?</p>
  
  <p>Additionally, I have tried getting the total streams and dividing by 100 (+1) and doing it differently not using the "next" URL but that code was so messy compared to this - assuming I can get this to work.</p>
  
  <p>Thanks!</p>