Twitch Tv Project Help

Twitch Tv Project Help
0

#1

Hey, fellow coders!
I need some help! I’m running into some difficulties with my twitch app.
I can’t seem to display both online and offline data it only seems to display online at the moment.

I’ve included the link to my app below! Any solutions would be appreciated!


#2

I looked in the developer tools of chrome while your app was on codepen, and I saw the following error:

pen.js:44 Uncaught TypeError: Cannot read property ‘game’ of null
at Object. (pen.js:44)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at A (jquery.min.js:4)
at XMLHttpRequest. (jquery.min.js:4)

Line 44 of pen.js is:

var game = data2.stream.game;

If the stream is offline, it is coming back as null, throwing an error, and the app is then unresponsive. A fix to this would be to set up conditionals that check for a null value, then in the logic, set that stream to “offline”. Something like the following:

    $.getJSON(makeURL("streams", channel), function(data) {
        var game,
            status;
        if (data.stream === null) {
            game = "Offline";
            status = "offline";
        } else if (data.stream === undefined) {
            game = "Account Closed";
            status = "offline";
        } else {
            game = data.stream.game;
            status = "online";
        };

#3

I haven’t done this project yet but on line 58 where you append the html there is

if (streamInfo === null) { ...

null means there is no value right. But I think what you’re after is to check if they’re on/offline.

logging out the contents of streamInfo shows objects for online streamers and null for offline. As in there is no offline info to push to your tables. which is why the console os showing typerrors for props like .game and .viewers

Might have to figure out a different way to sort on/offline streamers. Check a status or something similar before hand.


#4

Thank you so much for your help I was able to fix the problem!


#5

Now I’m just a little stuck on how to make the links reveal online and offline data when clicked.


#6

Thanks Dylan for your feedback I was able to fix that issue.


#7

Hi Campers,

Please I need help here…when I do a console log on my offline twitch data, it comes in as undefined and the output is not able to display correctly. Please help.Here is my codepen below.
https://codepen.io/thinkC/pen/rmRGLG

Thanks