Really stuck at twitchTV project

I really got stuck at the twitchtv project. I know I shouldn’t look at example code. I am able to work those who streaming, but i have trouble getting information of those user who are offline. Any suggestion at would be greatly appreciated. and also when to display all users either offline or online in one page. HELP PLEASE!!!

2 Likes

This what I did
var userList="";
for(var i =0 ; i< twitchUsername.length; i++){
userList+= twitchUsername[i]+’,’;
}
$.ajax({
url:‘https://api.twitch.tv/kraken/streams/’,
data:{channel:userList},
dataType:‘jsonp’,
type:‘get’,
success:function(data){ //do something here }
});

all i get from this only those who are online, not those who are offline. it takes me almost 2 week now, but I could make it works.

Do you have a codepen?

Actually for the channels which are offline you need to hit a different url for that which is https://api.twitch.tv/kraken/channels/" so you need to check whether the stream is null if it is you gotta hit the above mentioned url to get the data.

3 Likes

Yes, here is a link: http://codepen.io/weebuzer/pen/wzaVvb?editors=1010 it doesn’t work as the requirement needed.

So that means i need to run different $.ajax(); right?

And also if the channel is not online then i don’t have access to those channel logo for display on the page.

Yes, this is how twitch api is. For offline channels you don’t get any detailed info. So you need one call to learn who is online and offline and another for getting offliners logos.

1 Like

Yeah that’s is the reason why you have to hit the different url, the one that i mentioned in my previous comment. When you hit the url for getting the info about the online users there’s a property there you can check if the users are offline which is streams, so you need to check if the stream is null for the channel you’re passing and if it is indeed null, you gotta make another ajax request with the url i mentioned before.

1 Like

:disappointed_relieved:

I had to skip this one. maybe come back for it later.

thanks this saved my day

1 Like

Hi,

You can also use /channel in a seperate call to /streams.

This will give you more info for those off line channels.

Perhaps you could trigger an api call with /channel if you recieve a response with an array length of 0, you could trigger a new API - this /channels response doesn’t tell you if they’re online or not though so you would still initially have to use /stream.

Personally I just didn’t display the ofline channels. I had a list instead and changed their color there whilst putting the online users on the main section with all the extra info required. Afterall, the /streams response that tells you they are offline gives you nothing to parse anyway.

(applogies if this has already been posted but i havn’t read the whole thread.)

Cheers

Mark

Glad I could help!:slight_smile:

I’ve been stuck in this project for several months already. Going back to writing pseudocodes and hope for the best. :smiley: