Twitch API console logging the Data

Twitch API console logging the Data
0.0 0

#1

I am stuck obtaining the data of the twitch using the pass-through of FCC . here is the code I tried:

 $.ajax({
 type: 'GET',
 url: 'https://wind-bow.gomix.me/twitch-api/streams/freecodecamp',
 success: function(data) {
   console.log(data);
 },
   error: function(){
     alert("error!")
   }
 });

I tried changing dataType to ‘json’, async to false. but with no luck

I also tried doing

$.get("https://wind-bow.gomix.me/twitch-api/streams/freecodecamp" , function(data){
console.log(data)
};

I tried this using POSTMAN and it works just fine, it returned me the strings needed but I can’t seem to do it in codepen.io. Here is my code https://codepen.io/bradrar1/pen/ZoRLVj?editors=0002


#2

When I run your code, I get the following error in the browser console:

Failed to load https://wind-bow.gomix.me/twitch-api/streams/freecodecamp: Redirect from ‘https://wind-bow.gomix.me/twitch-api/streams/freecodecamp’ to ‘https://wind-bow.glitch.me/twitch-api/streams/freecodecamp’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://s.codepen.io’ is therefore not allowed access.

Learn to read your browser console. It is the most valuable tool a web dev has, only second to coffee.

CORS is an issue all to itself. I’m not sure why it is an issue here, but a little research shows that the url string has changed. When I try:

 url: 'https://wind-bow.glitch.me/twitch-api/streams/freecodecamp',

I get a good response in codepen.

Let us know if it still isn’t working.

Yes, APIs are confusing, especially when you are learning. Your struggles are typical.


#3

@kevinSmith Thanks, I thought that codepen’s console is the same as my browser’s console so I ignore my browser’s console and hoping some explanation would appear in codepen console. Now that I see the issue . I have resolve it by changing the URL. Thank you for the explanation .


#4

Yeah, I made that same mistake when I was learning. The codepen version leaves out a lot of the errors, unfortunately.