Twitch.tv challenge

Is there something I’m missing here? I can get channel info for a particular channel by sending a request to

https://api.twitch.tv/kraken/channel/

and I can get stream info for a particular channel by calling

https://api.twitch.tv/kraken/streams/

The channel information will tell me if a user doesn’t exist, but it won’t tell me if the user is streaming or not.
The stream information will tell me if a user is streaming or not, but won’t tell me if the user exists.

To make matters worse, I can only query one user at a time? So if I want to get results for an array of usernames, I have to loop through the array sending two requests to the API each time?

This seems awfully convoluted to me and I’m sure I must be missing some way to get more data with a single ajax call.

EDIT: Well, I’ve completed the challenge. I figure I’ll post my approach here so that if anyone has the same questions later on, it might serve as a reference for them.

The way I handled this was by looping over an array of channel names.

For each channel, the first thing to do was to call the /channels/ stream to see if the channel existed or not. If the channel did not exist, then I created the HTML for that display.

Next, (else -> channel does exist), I called a function that generated a bit of generic HTML for channels that do exist, using information from the /channels/ stream. Fortunately, this includes just about everything I wanted (icon, channel display name, channel url). This function actually used the channel’s display name to give the div for each channel name an individual ID.

Finally, a separate ajax call was made to the /streams/ stream. This checked whether the channel was broadcasting live or not, and edited the HTML created in the previous step to reflect the online status.

It was quite a tricky thing to pull off, and I learned a lot along the way.
Here’s the result.

1 Like

Yeah, you did well. Often times you don’t get the data you want, so you have to make do with whatever logic you can write on your end to infer from what you get. As for the number of queries, that’s just entirely on them, but if you’ve got client credentials and you’re under any specified limit, then it doesn’t really matter much. I’m currently creating a personal project using Spotify’s API. They require user authentication to get album and track data, which means I can’t cache the data and a new call (or five) has to be made every time the user changes a slide. Inefficient? Yeah, totally, but there aren’t any usage limits and it’s all by their design so what can I do?

Interesting. Well, at the end of the day, as long as it works, it works!