Twitch with supplied data

I came across the post that provided the data that the Twitch API would return. I’m using that in my project but I dont see any field that indicates whether the user is streaming or not (online or offline). How do we make that determination?

The response https://wind-bow.gomix.me/twitch-api/streams/username will contain a property call stream. If it is null (like in the case for freecodcamp right now), it means it is not streaming and will look like:

{
  "stream": null,
  "_links": {
    "self": "https://api.twitch.tv/kraken/streams/freecodecamp",
    "channel": "https://api.twitch.tv/kraken/channels/freecodecamp"
  }
}

If stream is not null, then it is streaming and you will get more information about the stream like in the following response:

{
  "stream": {
    "_id": 27708760768,
    "game": "Overwatch",
    "viewers": 151205,
    "video_height": 1080,
    "average_fps": 59.9400599401,
    "delay": 0,
    "created_at": "2018-02-23T23:45:58Z",
    "is_playlist": false,
    "stream_type": "live",
    "preview": {
      "small": "https://static-cdn.jtvnw.net/previews-ttv/live_user_overwatchleague-80x45.jpg",
      "medium": "https://static-cdn.jtvnw.net/previews-ttv/live_user_overwatchleague-320x180.jpg",
      "large": "https://static-cdn.jtvnw.net/previews-ttv/live_user_overwatchleague-640x360.jpg",
      "template": "https://static-cdn.jtvnw.net/previews-ttv/live_user_overwatchleague-{width}x{height}.jpg"
    },
    "channel": {
      "mature": false,
      "partner": true,
      "status": "Stage 2 Week 1 Day 3 | London Spitfire vs. New York Excelsior\n",
      "broadcaster_language": "en",
      "display_name": "OverwatchLeague",
      "game": "Overwatch",
      "language": "en",
      "_id": 137512364,
      "name": "overwatchleague",
      "created_at": "2016-10-20T21:24:38Z",
      "updated_at": "2018-02-24T01:06:42Z",
      "delay": null,
      "logo": "https://static-cdn.jtvnw.net/jtv_user_pictures/bbecd8c4-141c-422b-8285-e3f8cae79dbb-profile_image-300x300.jpg",
      "banner": null,
      "video_banner": "https://static-cdn.jtvnw.net/jtv_user_pictures/81b494af1f63064d-channel_offline_image-1920x1080.png",
      "background": null,
      "profile_banner": "https://static-cdn.jtvnw.net/jtv_user_pictures/0b3c5521-8aae-4a78-ba42-2d44e0734cd9-profile_banner-480.png",
      "profile_banner_background_color": "",
      "url": "https://www.twitch.tv/overwatchleague",
      "views": 31888490,
      "followers": 689281,
      "_links": {
        "self": "https://api.twitch.tv/kraken/channels/overwatchleague",
        "follows": "https://api.twitch.tv/kraken/channels/overwatchleague/follows",
        "commercial": "https://api.twitch.tv/kraken/channels/overwatchleague/commercial",
        "stream_key": "https://api.twitch.tv/kraken/channels/overwatchleague/stream_key",
        "chat": "https://api.twitch.tv/kraken/chat/overwatchleague",
        "features": "https://api.twitch.tv/kraken/channels/overwatchleague/features",
        "subscriptions": "https://api.twitch.tv/kraken/channels/overwatchleague/subscriptions",
        "editors": "https://api.twitch.tv/kraken/channels/overwatchleague/editors",
        "teams": "https://api.twitch.tv/kraken/channels/overwatchleague/teams",
        "videos": "https://api.twitch.tv/kraken/channels/overwatchleague/videos"
      }
    },
    "_links": {
      "self": "https://api.twitch.tv/kraken/streams/overwatchleague"
    }
  },
  "_links": {
    "self": "https://api.twitch.tv/kraken/streams/overwatchleague",
    "channel": "https://api.twitch.tv/kraken/channels/overwatchleague"
  }
}
1 Like

Yes, I saw all that. In the sample application that we are reverse engineering, there were 2 users showing as offline but they both showed icons. In the case where stream = null, there is no icon element so that threw me off. I guess I’ll just force a default icon along with the user name and an “offline” indication in this case. Thanks.

If you want to get the actual icon for the username, then you can use the other endpoint (https://wind-bow.glitch.me/twitch-api/users/username) and it has a logo property you could use.