I need some help with the Twitch.tv API project challenge. I’m totally stuck. I also have errors about CORS refusal so I’m worried about that too. I hope someone will point me to the right direction on what I should do.
Okay, thanks. And yeah, I have a 200 response status. This is what I have now: https://codepen.io/DragonOsman/pen/abOvqEN . Am I doing I shouldn’t be in here? And if I want to try and log the whole response to see what I have and how I could get what I want from it, how do I do it correctly in this loop? With what I had before, where I was doing console.log(data) in the second .then(), I was getting only 1 length arrays that didn’t have the data I needed.
Yeah, thanks. I at least have the info. I just don’t get how I should display the info. Are the two divs I have enough or should I put more stuff in there first?
This is what I have now. It’s still off. It seems I need to get deeper in. I need to do something similar to this. How do I see if a streamer is online or not? Maybe I need to use a different endpoint for that.
I advise you to register on tvitch tv and get your own client-id. You need only client-id to build your own app straight from tvitch tv.
You find also documentation how to use the twitch tv api. It is not too difficult…
The FCC guys want us to do without having to use the client-id. So they even have a wrapper for the base URL for the API endpoints. I’ll still get the client-id to learn it though, I guess.
That’s in data.data[0]? So what’s the correct way to access it? Object.entries or something else? And yeah, I’ll look into the other endpoints for the online/offline data.
Edit: I’m getting these stuff printed out on the page:
You keep overwriting the innerHTML. Try concatenating the string infoDiv.innerHTML += ${key}: ${value} ;
You may have to use the cached version https://wind-bow.glitch.me/twitch-api to get to some of the data. BTW, you don’t have to use the fCC proxy API. It is not a requirement, it is just there so you don’t have to sign up for a client ID.
Sure if all you have is a string you can use textContent, but you still need to not overwrite it.
For this project, I’m not sure how bad it is to leak the ID. And technically you can just pass the tests and then delete the ID. Otherwise, you would have to find some solution. Like for example setting up your own backend API to proxy the requests (here is a video you can check out with an example of this).
If you just want some practice with using APIs and doing some light DOM manipulation using that API data you can find a bunch of free APIs to use.
But if you want to do this assignment I would suggest approaching it like a larger app possibly with both front and back ends and using the real Twitch API. As said, with a backend you can have it handle the API requests and your client will fetch the data through your backend. It is a lot more work but will also teach you some important stuff.
Remember this is just a pretend “take-home” assignment for you to get more practice.
This is what I have now. I need to show who is currently streaming, right? But I can’t figure out how to do that. Do I need a different endpoint or do I just use the description property in the data?
I tried to get an access ID but it seems I need two-factor authentication which I don’t know how to get.
Pretty sure you have to use the cache endpoint. The channels endpoint will give you channel info and the streams will give you stream info. On the streams endpoint, the stream property will be null if there is no stream, otherwise, it will have info on the current stream (game played, etc.).
So it’ll be fine if I just use the streams cached endpoint? Since the stream property on that tell me if there’s a current stream going on. I’ll try this.
Actually, now that I look at it, you can use the https://wind-bow.glitch.me/helix/streams?user_login= endpoint. If the stream is live the data array will have an object in it with the stream info, otherwise it will be empty.
Pen. I have an error in the JavaScript code, sometimes on line 19 and sometimes on line 21, saying:
Uncaught SyntaxError: missing ) after argument list
Why am I getting that and how do I fix it?
If the person is currently streaming, the data property on the object returned by /streams?user_login=<user_name> will have stuff and it’ll be an empty array otherwise, right? And the way to get to that array is data["data"]? Or what?