TwitchTV is making my brain glitch

TwitchTV is making my brain glitch
0.0 0

#1

Hello all,

I am trying to work on the TwitchTV app. I am the first to admit that I feel less than confident about. I have gotten this far in the curriculum and I am feeling frustrated because I don’t feel like I fully understand what I did that worked and why I did it. But the research I have done so far hasn’t resolved this.

1st question:
Is there a good resource to fill in the gaps in knowledge about what I am doing (any time I try to make a call to an API for data)? The resources are either not comprehensive enough, encyclopedic in their breadth (like MDN) which causes my brain to overload, or to specific while being general (the Twitch Documentation). Or maybe I am skimming over the information I need. I don’t know.

2nd question:

What am I doing wrong? I seem unable to get any response. I am not seeing anything happen in the code-pen console. The only thing showing in the Chrome console is a CORS error message from the Code-pen site that is unrelated to my code.

let request = new XMLHttpRequest();

let url = "GET https://wind-bow.gomix.me/twitch-api/streams/freecodecamp";
let data;

request.open("GET", url, true);


request.onload = function(){

  if (this.status >= 200 && this.status < 400) {
  
     data = JSON.parse(this.response);
    
     console.log("Success!  That's right!");
     console.log(data);
   
  } else {
    
    console.log("error. It's a freaking 404");
  }
  
request.send();
}



Thanks,
Gabe


#2

let request = new XMLHttpRequest();

let url = “https://wind-bow.gomix.me/twitch-api/streams/freecodecamp”;
let data;

request.open(“GET”, url, true);

request.onload = function(){

if (this.status >= 200 && this.status < 400) {

 data = JSON.parse(this.response);

 console.log("Success!  That's right!");
 console.log(data);

} else {

console.log("error. It's a freaking 404");

}

}
request.send();

try this…
let request = new XMLHttpRequest();
let url = “https://wind-bow.glitch.me/twitch-api/streams/ESL_SC2?callback=”;
let data;
request.open(“GET”, url, true);
request.onload = function(){
if (this.status >= 200 && this.status < 400) {
data = JSON.parse(this.response);
console.log(“Success! That’s right!”);
console.log(data);
} else {
console.log(“error. It’s a freaking 404”);
}
}
request.send();


#3

Thanks guiidd!

Now I can go to bed. If I am seeing things correctly there were 2 issues. The one was that I had the wrong url (go-mix vs. glitch). And the other is that because of where I placed the request.send() function call it never got called. The request.send() call is the function call that initiates communication with the API but I had it tucked inside it’s own function declaration. Is that right? I may not have all the terminology right so I hope that makes sense.

Either way thank you!


#4

This link helped me somehow…read it if u have the time. Good luck…


#5

Hey guiidd,
Thanks. This link is the most helpful explanation I have seen yet.

You are a lifesaver!