hi im trying to complete twitch.tv challenge and am using the api workaround suggested by fcc but it doesnt seem to be working. I am referring to number 9 in the project’s descripiton/instructions:
“UPDATE: Due to a change in conditions on API usage explained here Twitch.tv now requires an API key, but we’ve built a workaround. Use https://wind-bow.gomix.me/twitch-api instead of twitch’s API base URL (i.e. https://api.twitch.tv/kraken ) and you’ll still be able to get account information, without needing to sign up for an API key.”
Here is my js code:
$(document).ready(function(){
var online;
var offline;
var all;
var fcc;
var channels = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
var channelName;
var channelID;
var channelLogo;
var streamingInfo;
var channelURL;
$.each(channels, function (i, val) {
$.getJSON("https://wind-bow.gomix.me/twitch-api/streams/" + val, function (st) {
channelName = val;
if (st.stream == null) {
$.getJSON("https://wind-bow.gomix.me/twitch-api/channels/" + channelName, function (ch) {
channelID = channel.display_name;
channelLogo = channel.logo;
streamingInfo = channel.status;
channelURL = channel.url;
if (channel.status == '404') {
$("#invalid").append(channel.message);
} else if (st.stream == null) {
$("#offline").html('"' + channelLogo + '"');
} else {
$.getJSON("#online").html('"' + channelID + '"');
}
});
}
});
});
});
Still doesn’t work for me. I’m getting CORS error.
function twtch() {
var url = 'https://wind-bow.gomix.me/twitch-api/streams/ESL_SC2?callback=?';
var get = new XMLHttpRequest();
console.log('UNSENT ',get.readyState);
get.open("GET", url, true),
console.log('OPENED ',get.readyState);
//get.setRequestHeader('application', 'vnd.twitchtv.v5+json'),
get.send(null),
console.log('HEADERS_RECEIVED ',get.readyState);
get.onreadystatechange = function () {
console.log('LOADING? ',get.readyState);
if (get.readyState === 4 && (get.status === 200)) {
var data = JSON.parse(get.responseText), html = '';
function print() {
for (var i = 0; i < data.data.length; i++) {
let width = 400, height = 400;
html += '<li class="feature-box">'+data.data[i].user_id+'</li><li>'+data.data[i].title+'</li>';
}
html += '<ul>';
document.getElementById('twitchy').innerHTML += html;
}
html += '</ul>';
print();
}
}
}
I’m getting 301 redirect, but “no response data” and the following error message in console:
Failed to load https://wind-bow.gomix.me/twitch-api/streams/ESL_SC2?callback=?: Redirect from 'https://wind-bow.gomix.me/twitch-api/streams/ESL_SC2?callback=?' to 'https://wind-bow.glitch.me/twitch-api/streams/ESL_SC2?callback=?' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.