I’m having issues nesting my Twtich.api request to go specifically to the user that will be using my app. Currently, I have the following lines:
Twitch.api({method: ‘streams’}, function(error, streams) {
console.log("View count is: " + streams.viewers);
});
This however, returns an array of all active streams, it shows all their view counts. How do I go about nesting my request to be specific to my user only? I have the user logged in, i find their display name, stream key, _id, and follower counts with ease (as these do not require nesting). I have thought about doing a for loop and looping through all of the active streams until I find one that matches the _id of my user but that seems rather tedious and lenghty. How do I go about narrowing down my search
I may be misunderstanding the question, but are you looking for the /streams/:channel endpoint? Are you trying to get the viewer count for only your user or is there other data that you are trying to gather?
Ok, so, the /streams/:channel endpoint will return data if online, but not offline. So, if you want to get the active viewer count, yes, use /streams/:channel (i.e. /streams/illusionaryone). Now, if you want to get total views ever on the channel I would recommend the /channels/:channel (i.e. /channels/illusionaryone) endpoint, which will return the views data member off the primary object if the user is offline or online.
In your case, let us say your user name is IllusionaryOne (me). You would access /streams/illusionaryone :channel is just a placeholder to say put the channel/user name you want here. So, put the name of the user that you are trying to get in the place of :channel
Ah ok, that was pretty helpful it solved my first problem
I can now narrow my search down to the user specifically, and I can see their view count but when I try to console.log their view count I’m unsure what to write to get it. Not sure if that makes sense, currently I have
console.log("View count is: " + channel.viewers);
But that just returns undefined so clearly my +channels.viewers is not correct
I have found this information about my user. It shows that there is currently 1 Viewer watching.
How do I access this number specifically and put it into a variable or for now a console.log statement that would just say
“THE STREAMER HAS 1 VIEWER” kinda thing