Use the Twitchtv JSON API: Cross-Origin Request Blocked

Use the Twitchtv JSON API: Cross-Origin Request Blocked
0.0 0

#1

Hey everyone, I’m trying to complete the project that involves the Twitchtv JSON API but I’m having trouble getting data from Free Code Camp’s Twitch API Pass-through (https://wind-bow.gomix.me/twitch-api). When I attempt to access data from the /streams/:stream route, I get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://wind-bow.gomix.me/twitch-api/streams/freecodecamp. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Has anyone come across this error?

I’m using the fetch API to make the request.


#2

At the end of your API call add “?callback=?”


#3

I get the same error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://wind-bow.gomix.me/twitch-api/streams/freecodecamp/?callback=?.


#4

I think the easiest way to get around the Cross-Origin issue for this project is to use JSONP, but I’m not sure that it’s supported by fetch().
So I guess one solution is to use jQuery’s ajax(), and another is to keep using fetch(), but also figure out how to work with CORS.


#5

Thanks for your response. I ended up switching to jQuery’s getJSON method.