What field and in which of these links should I be checking? I was able to see the users data and I don’t see anything relating to online or offline.
{
"_links": {
“teams”: “https://api.twitch.tv/kraken/teams”,
“channel”: “https://api.twitch.tv/kraken/channel”,
“user”: “https://api.twitch.tv/kraken/user”,
“ingests”: “https://api.twitch.tv/kraken/ingests”,
“streams”: “https://api.twitch.tv/kraken/streams”,
“search”: “https://api.twitch.tv/kraken/search”
},
…
}
Thanks.
_links
doesn’t apear to be much use, it looks like a collection of generic links.
In my solution, I queried https://api.twitch.tv/kraken/streams/<userName>
and checked if stream
in the response was null
or not.
For example, in this screenshot, OgamingSC2 is online because stream
is not null
, whereas cretetion is offline:
I then used stream.channel.url
to access the users’ actual streams if they were online.
You can use my pen at http://codepen.io/janschreiber/full/xEXJbr and inspect what’s going on there in the network tab of your browser’s dev tools.
I’m not saying that my method is particularly elegant, though. I discovered this method by experimenting with users I knew were online or offline, respectively.
Hi,
I checked the actual actual object structure of the response from calling streams.
[details=spoiler]if (response.hasOwnProperty('stream') && (response.stream !== null)) { //if channel is online {object}
and
else if (response.hasOwnProperty('stream') && (response.stream === null)) { //if channel is offline {object}
[/details]
Cheers
Mark
edit - which is exactly what @janschreiber said
Hi @janschreiber,
Thanks for the information. I will give it a try.
Hi janshchreider,
Where did you learn the HTML and CSS in such detail? Also, how did you know to use streams and channels? This was really difficult to find information. Thanks.
Thanks Markj78 for your response to calling the object.
That was the hardest part to figure out. Truth be told, I was two steps shy of quitting Free Code Camp because of this very project. In my opinion, it is the most difficult one required for the front-end certification.
The requirement of an app id had been introduced by the Twitch people just a few days before I started working on it and it was a somewhat messy experience because I was totally new to using AJAX/JSON. But I kept checking back on this forum and GitHub and managed to piece it all together somehow. It was reassuring to see that the FCC team on GitHub was already working on solutions while I was struggling with the challenge.
Well, after some struggling it turned out that the most important piece of information had been there all the time on the page https://www.freecodecamp.com/challenges/use-the-twitchtv-json-api. It says in instruction #8:
Hint: The relevant documentation about this API call is here: https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamschannel.
The link above is where I got the crucial information that I had to use streams
to determine the online status of a user. It is a bit cryptic, but I relied on my experience that FCC challenges always supply you with enough information to get you started, and yes, the necessary information was right there, it was just a bit harder to identify than usual.
Everything else fell into place somehow after I was able to get a useful response from the server. I had the developer tools of my browser open most of the time.
Well, the short answer is: I am 43 years old and started learning HTML 4.01 back in 2003 or something as a hobby. I worked through an online course back then and built a few (now defunct) websites. That gives me a bit of background knowledge so I know what to google for.
But basically, I just google everything I don’t know. A few example searches:
- css rounded corners - Google Search
- javascript nested loop - Google Search
- html5 header - Google Search
- css background color - Google Search
These searches will usually refer me to a number of trustworthy websites: