Created
April 24, 2017 19:38
-
-
Save the-vampiire/2bcc80bf3fa237e7e3e3ccbaa34e4e06 to your computer and use it in GitHub Desktop.
Get User by OAuth Token
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
// 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