Live status Javascript

Hello,
I’m trying to adapt a browser extension that shows whether the streamer is online or not.
I can not adapt the code to the new API
Do you have any leads?

app.js : 
        var xhr = new XMLHttpRequest()
    xhr.open("GET", "https://api.twitch.tv/kraken/streams/platiscript?client_id=XXXXXXXX", true)
    xhr.onreadystatechange = function(channel) {
      if(xhr.readyState == 4) {
        var data = JSON.parse(xhr.responseText)
        var elm  = document.getElementById("info")
        if(data["stream"] === null){
          elm.style.color = "red"
          elm.innerHTML = "La SubData TV n'est pas en live actuellement :("
        }else{
          elm.style.color = "green"
          elm.innerHTML = "Viens voir SubData en live maintenant !"
        }
      }
    }
    xhr.send()

background.js :

function checkStream() {
  var xhr = new XMLHttpRequest()
  xhr.open("GET", "https://api.twitch.tv/kraken/streams/LeFresechReream?client_id=XXXXX", true)
  xhr.onreadystatechange = function () {
    if(xhr.readyState == 4) {
      var data = JSON.parse(xhr.responseText)
      if(data["stream"] === null){
        chrome.browserAction.setIcon({path:"img/icon_red.png"})
      }else{
        chrome.browserAction.setIcon({path:"img/icon_green.png"})
      }
      // On relance la fonction après X secondes
      setTimeout(checkStream, tickRate)
    }
  }
  xhr.send()
}

Thank

The docs for getting a stream in the new API are here: https://dev.twitch.tv/docs/api/reference/#get-streams

So the main changes you’ll need to make are using the user_login querystring param to specify the user (if you wish to continue doing it by their username) rather than as part of the path. You’ll also have to include your client id as the Client-ID header, you can’t send it as a querystring param any more. Finally, the results you get back will differ so you will need to look at how the response differs as shown in the example on the docs page and adjust as accordingly.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.