Hi!
I want to display my channel status to my website visitors (site is based on wordpress).
Right now I’m using special widget for this-but it loads up stream instantly (=>consumes traffic) and also uses Flash, which loads up users’ CPU and loads relatively slowly on its own.
I also have very basic knowledge of HTML and JS.
What I want to do now is a simple “text box” (which allows HTML and js), where I could place script that looks like:
IF channel is live THEN display img with link via innerHTML
ELSE (f channel is offline) display another image with same link via innerHTML
So, how do I write this? I don’t know how to “ask” server for channel status, and I barely know how to realize that function.
$.getJSON('https://api.twitch.tv/kraken/streams/' + YOUR_CHANNEL_NAME, function(channel) {
if (channel["stream"] == null) {
//THEY ARE OFFLINE DO WHATEVER HERE
} else {
//THEY ARE ONLINE DO WHATEVER HERE
}
});
Thank you for a quick response!
I’m trying to implement this, but there should be an error somewhere in this code. How can I debug/search for it? Maybe you can show me, where it is?)
Screenshot: http://puu.sh/h8IAK/6fa92aad63.png
Code snippet: http://pastebin.com/hMKyM4Md
Sorry, I just looked at your screenshot and now I see the issue. I thought you meant the CORS error that is displayed when querying the endpoint without jsonp.
You need to include a script reference to jQuery before making the request like so:
Alright guys, thank you very much for your answers.
Final piece of code that seems to work, in case anybody will stumble upon this page while googling for the same problem. Idea was to display different images of Twitch channel logo depending on status is LIVE or not, and existing wordpress plugins or other solutions were not suited for me, because I wanted exact image with exact size.