# Need help with the Twitch API project

**URL:** <https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737>\
**Category:** General\
**Created:** [August 30, 2017, 7:27am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737 "2017-08-30T07:27:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [August 30, 2017, 7:27am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/1 "2017-08-30T07:27:46Z")

</div>

I was working on the Twitch API project. I intend the page to show logo, name and status of different channels. If the channel is not streaming, the status is offline, but the name and logo is still displayed. However, using the [https://wind-bow.gomix.me/twitch-api](https://wind-bow.gomix.me/twitch-api) api, when the channel is not streaming, I can’t get relevant information about name and logo. I don’t know what to do. And when the channel is online, according to the page I can get the information I want. However, the page shows undefined.  
Here’s my code.  
[https://codepen.io/Minyang64/pen/PKyWje](https://codepen.io/Minyang64/pen/PKyWje)

---

<div class="post-metadata">

**Author:** ![TheGallery](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thegallery/32/161197_2.png) [@TheGallery](https://forum.freecodecamp.org/u/TheGallery)\
**Post date:** [August 30, 2017, 10:36am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/2 "2017-08-30T10:36:25Z")

</div>

[The API](https://wind-bow.glitch.me/) also has the `/users/:user` and `/channels/:channel` endpoints which provide user data. `/streams/:stream` provides stream data.

---

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [August 30, 2017, 11:24am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/3 "2017-08-30T11:24:31Z")

</div>

I set the url to /users/:user endpoint and found the name and logo information. Thank you. However, there’s another problem regarding the /streams/ end point. When I access this page with a browser, I can see a status attribute which describes the broadcast content. However, when using console.log(data) at Codepen, the data seems different. And I cannot find the status information.

 ![tp2](https://global.discourse-cdn.com/freecodecamp/original/3X/7/0/709e4081ac522c860cb601db481f4efc55888af9.png) ![tp1](https://global.discourse-cdn.com/freecodecamp/original/3X/3/0/30ef2e89edcc65c5c92aeb229a6eba1162ac1767.png)

---

<div class="post-metadata">

**Author:** ![TheGallery](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thegallery/32/161197_2.png) [@TheGallery](https://forum.freecodecamp.org/u/TheGallery)\
**Post date:** [August 30, 2017, 11:33am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/4 "2017-08-30T11:33:27Z")

</div>

You are showing me the stream object, status is in the channel object.

---

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [August 30, 2017, 11:41am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/5 "2017-08-30T11:41:20Z")

</div>

Oh, I see. Thank you for pointing out.

---

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [September 1, 2017, 1:03pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/6 "2017-09-01T13:03:36Z")

</div>

I modified my code. I intended to loop through the channels from the list with the /streams site. If the channel is not streaming, set the status to offline and go to

the /users site to get the name and logo. Otherwise get the status, name and logo from the /streams site. Also, I want the name linked to the streaming page. I still

can’t get the name and logo when the channel is offline. Using console.log(), I found the information of living channel is passed to the {stream===null} condition. I

have no idea what’s wrong with my for loop and if statement.

---

<div class="post-metadata">

**Author:** ![TheGallery](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thegallery/32/161197_2.png) [@TheGallery](https://forum.freecodecamp.org/u/TheGallery)\
**Post date:** [September 1, 2017, 4:51pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/7 "2017-09-01T16:51:33Z")

</div>

The response from the `/users` API should contain the logo and the name. Can I see your code so far?

---

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [September 1, 2017, 6:03pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/8 "2017-09-01T18:03:22Z")

</div>

> **[TwitchTV Json API](https://codepen.io/Minyang64/pen/PKyWje)**
>
> ...

---

<div class="post-metadata">

**Author:** ![TheGallery](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thegallery/32/161197_2.png) [@TheGallery](https://forum.freecodecamp.org/u/TheGallery)\
**Post date:** [September 1, 2017, 7:05pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/9 "2017-09-01T19:05:48Z")

</div>

By the time your `url` requests are done, your `for` loop has ended and `url2` has the value of the last stream. There are various ways to overcome the issue, but I’d suggest you use Array.forEach for now instead of a `for` loop (A `for` loop with `let` instead of `var` would work the way you intented it to). Convert your loop like this:  
 ![scope](https://global.discourse-cdn.com/freecodecamp/original/3X/6/7/6744fa85d2cfccb7525c8186b53e8540bf487894.png)  
and you’ll be fine with scope-wise. If you are not familiar with context and scopes in JS, please go study those concepts.

Keep in mind that in your current implementation, your page will not update with offline channel data, because your url2 requests won’t be finished before you update the UI. You’ll need to call $(’#details’).prepend() inside the url2 handler as well for the offline streams.

---

<div class="post-metadata">

**Author:** ![MinyangWang](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/minyangwang/32/64037_2.png) [@MinyangWang](https://forum.freecodecamp.org/u/MinyangWang)\
**Post date:** [September 4, 2017, 7:33am UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/10 "2017-09-04T07:33:20Z")

</div>

Problem solved. Thank you very much.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:40pm UTC](https://forum.freecodecamp.org/t/need-help-with-the-twitch-api-project/144737/11 "2021-01-17T20:40:37Z")

</div>

Closed on January 17, 2021, 8:40pm UTC


