Hey guys I really appreciate everyones help! I finally got this solved
!!!
Implementing the request-promise module and using the .then() helped a lot
I also implemented default values for the responses that get overwritten in the game request.
Code:
function getJSON(callback){
var options = {
uri: 'https://api.twitch.tv/kraken/streams/',
qs: {
game: 'overwatch',
limit: 2
},
headers: {
Accept: 'application/vnd.twitchtv.v5+json',
'Client-ID': clientID
},
json: true // Automatically parses the JSON string in the response
}
rp(options)
.then(function (jsonResponse) {
var result = jsonResponse.streams[0].channel.display_name;
streamers.push(result);
if (streamers.length <= 0){
callback("ERROR");
}else{
callback("SUCCESS got streamers " + result);
}
})
.catch(function (err) { // API call failed...
callback("I'm sorry, something went wrong when trying to get streamers. " + err);
});
}