Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Created April 24, 2017 19:38
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/2bcc80bf3fa237e7e3e3ccbaa34e4e06 to your computer and use it in GitHub Desktop.
Save the-vampiire/2bcc80bf3fa237e7e3e3ccbaa34e4e06 to your computer and use it in GitHub Desktop.
Get User by OAuth Token
// Convert username to ID using OAuth (for logged in user)
function convert_username_OAuth(token){
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/user",
headers: {
"Client-ID": "vaiynh6nnd2nxpf6wshnj4v4zxxqz2",
"Accept": "application/vnd.twitchtv.v5+json",
"Authorization": "OAuth "+ token
},
success: function(data){
// call get_user_channels passing the ID gained in this request
get_user_channels(data._id);
}
});
}
// Get user channels
function get_user_channels(id){
$.ajax({
type: "GET",
url: "https://api.twitch.tv/kraken/users/"+id+"/follows/channels",
headers: {
"Client-ID": "vaiynh6nnd2nxpf6wshnj4v4zxxqz2",
"Accept": "application/vnd.twitchtv.v5+json"
},
success: function(data){
// empty the default channels
channel_names = [];
var i = 0;
// push user's followed channels into channel_names array
for(i; i < data.follows.length; i++){
channel_names.push(data.follows[i].channel.name);
}
// call convert_channels passing the now populated array of channel names
convert_channels(channel_names);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment