I’m sure that I am missing understanding a fundamental concept here but I am unable to access the Response headers to manage rate limiting using the new API from javascript. Here’s my code:
var twitchHelixHeaders = {
'Content-Type': 'application/json',
'Client-Id': 'bloominhellwhydoesntthiswork'
}
function getStream() {
$.ajax({
url: "https://api.twitch.tv/helix/users?login=" + channel,
headers: twitchHelixHeaders,
success: getStreamCallback
})
}
function getStreamCallback (data, status, response) {
//We are going to need to manage API call Rate Limits as the Helix API wil enforce Rate Limiting
console.log(response.getResponseHeader('Ratelimit-Remaining'));
console.log(response.getResponseHeader('Pragma'));
console.log(response.getAllResponseHeaders());
}
Basically it looks like the headers are not available to me in javascript using getAllResponseHeaders() however in the Chrome debugger I see the Response with all the required headers included.
This seems like a pretty common problem with javascript, possibly related to CORS but even if I try to enable CORS there is not any change. I’ve also noticed that if the API response includes an access-control-allow-headers list the ratelimit headers are not included but that actually doesn’t make any difference to the results I see in javascript I can only ever access the common headers and nothing custom.
Thanks for the suggestions but I get the same issue:
Got user data unshapedAdrian (45471252)
NaN/NaN calls remain for 0 seconds.
Basically from debugging it looks like the headers on the response are not available and so when I try to parse them out using your code I just get NaN.
I’m running this inside Chrome, I guess (as it worked for you) that you are running outside a browser is that correct.