I got it work!
First of all, this is a WordPress site and this is all in the backend, nothing is publicly exposed. All it does it store data into fields and then displays them.
Here’s what I got working:
$.ajax({
type: “POST”,
url: “https://id.twitch.tv/oauth2/token?client_id=<?php echo $client_ID;?>&client_secret=<?php echo $client_secret;?>&grant_type=client_credentials”,
header: {
“Content-Type”:“application/x-www-form-urlencoded”
},
success: function (data) { // authentication token
$.ajax({
type: “GET”,
url: “https://api.twitch.tv/helix/videos?id=1493894959”, // Video ID from URL
headers: { // this was giving me problems
“Client-ID”: <?php echo $client_ID;?>
“Authorization”: "Bearer " + JSON.parse(JSON.stringify(data.access_token)) // token from eariler AJAX
},
success: function (data) {
$(’.text’).text(JSON.stringify(data)); // show output
},
dataType: ‘JSON’,
});
},
dataType: ‘JSON’,
});
Thanks for the help!