Created
April 21, 2017 17:32
-
-
Save the-vampiire/a558ae2cc1e0cfc7d7ae01dccd020b10 to your computer and use it in GitHub Desktop.
Convert and Callback Stream Details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Stream Channel Names Array | |
var channel_names = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]; | |
// Stream Name to ID Conversion Request | |
function convert_username(arr){ | |
var i = 0; | |
for(i; i < arr.length; i++){ | |
$.ajax({ | |
type: "GET", | |
url: "https://api.twitch.tv/kraken/users?login="+arr[i], | |
headers: { | |
"Client-ID": "REDACTED", | |
"Accept": "application/vnd.twitchtv.v5+json" | |
}, | |
success: function(data){ | |
// callback the status and details request function | |
// passing the data (including ID) from this request | |
status_details(data); | |
} | |
}); | |
} | |
} | |
// Stream Status and Details Request | |
function status_details(data) { | |
// pulls ID attribute from convert_name data return which is passed to this request function | |
var id = data.users[0]._id; | |
$.ajax({ | |
type: "GET", | |
url: "https://api.twitch.tv/kraken/streams/" + id, | |
headers: { | |
"Client-ID": "REDACTED", | |
"Accept": "application/vnd.twitchtv.v5+json" | |
}, | |
success: function (data) { | |
console.log(data); | |
} | |
}); | |
} | |
// Document Ready (execute on page load completion) | |
$( function(){ | |
convert_username(channel_names); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment