Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Created April 21, 2017 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-vampiire/a558ae2cc1e0cfc7d7ae01dccd020b10 to your computer and use it in GitHub Desktop.
Save the-vampiire/a558ae2cc1e0cfc7d7ae01dccd020b10 to your computer and use it in GitHub Desktop.
Convert and Callback Stream Details
// 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