Hi Everyone
I’m relatively new to FCC and love it. I was looking for some feedback on the Twitch TV API project if that’s possible?
I use the following URL to check if a channel is streaming
https://wind-bow.glitch.me/twitch-api/streams/[channel display name]
If a channel is offline, the 1st name value pair returns “stream”: null.
If you look at the URL below (FCC’s channel which rarely streams you can see the ‘null’ value.
https://wind-bow.gomix.me/twitch-api/streams/freecodecamp
I’ve set up an ajax call (script below) to check if ‘null’ is returned.
$.ajax({
url: https://wind-bow.gomix.me/twitch-api/streams/freecodecamp,
dataType: “jsonp”,
success: function(data){
if(data.stream === null ) {
// channel offline
// do something
} else {
// channel online
// do something
}
}
});
When I run the ajax request, approximately 50% of the time I get an ‘undefined’ returned.
Here’s the page I’ve built
If I refresh my page a couple of times, the ‘undefined’ disappears
I’d be really grateful for any insights on what’s going on
In case it’s not above here’s the URL of my project https://hugoelliott.com/projects/twitch.html and here’s where the code is stored on GitHub https://github.com/hugo-elliott/hugoelliott.com
many thanks
Hugo