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.