Online Twitch Code - Please help

This is a copy of a code i am looking to use on a website, however i have two username that i know are live and one that is not how ever it shows off line or account closed!!

Can you help

//I toggle this to alternate flip style
var flipX = true;

//This seems like it could be refactored into several smaller functions…
function addStreamer(name){

//Request channel data
var url = “https://api.twitch.tv/kraken/channels/”+name;
$.getJSON(url,function(response){

//Get channel info
var stream = response.stream,
    pic = response.logo ? response.logo : "https://googledrive.com/host/0B4uAFl_t5LeDfm5GYXNBNlhIYjYtcVprM2sxSl9Ub3pUckhTcXN1UzZaSFJUd2R1QjV1Smc/static2.gif",
    status = response.status,
    link = response.url;

//Request streaming data
var url="https://api.twitch.tv/kraken/streams/"+name;
$.getJSON(url,function(response){
  
  //Streaming status
  var online = response.stream == null ? "offline" : "online";
  
  //Build streamer card html & add to list
  flipX = !flipX;
  var flipType = flipX ? "flipper" : "flipperX";
  var container = $("<div></div>",{title:status,class:"streamer "+flipType}),
      l = $("<a>",{href:link}),
      r = $("<div>",{class:"row"}),
      n = "<div class='streamer-name'>"+name+"</div>",
      p = "<img class='streamer-pic cell' src='"+pic+"'>",
      o = $("<div>",{class:'streamer-online cell'}).append(online);
  if (online != "online") o.css("color","#ccc");

  $("#streamers").append(l.append(container.append(r.append([p,n,o]))));
  
})

}).fail(function(){
var container = $("

",{title:status,class:“streamer flipper”}),
l = $("",{href:"#"}),
r = $("
",{class:“row”}),
n = “
”+name+"
",
p = “”,
o = $("
",{class:‘streamer-online cell’}).append(“account closed”);
o.css(“color”,"#ccc");
$("#streamers").append(l.append(container.append(r.append([p,n,o]))));
});
}

function showAll(){
$(".streamer").each(function(){
$(this).show();
});
}

function showOnline(){
$(".streamer-online").each(function(i,v){
if ($(this).text() == “offline” || $(this).text() == “account closed”) $(this).parent().parent().hide();
else $(this).parent().parent().show();
});
}

function showOffline(){
$(".streamer-online").each(function(i,v){
if ($(this).text() == “offline” || $(this).text() == “account closed”) $(this).parent().parent().show();
else $(this).parent().parent().hide();
});
}

function search(str){
$(".streamer-name").each(function(){
var n = $(this).text().toLowerCase();
console.log(n);
if (n.indexOf(str.toLowerCase()) > -1){
$(this).parent().parent().show();
}else{
$(this).parent().parent().hide();
}
})
}

function initialStreamers(){
var streamers = [“MedryBW”,“freecodecamp”, “storbeck”, “johnnymccrum”, “habathcx”,“RobotCaleb”,“jax_macky”,“noobs2ninjas”,“NoCopyrightSounds”,“brunofin”,“comster404”];
var delay=400;
streamers.map(function(v,i,a){
setTimeout(function(){
addStreamer(v);
},i*delay);
});
}

$(document).ready(function(){
//Create Default streamers
setTimeout(function(){
initialStreamers();
},1000);

$("#search-bar").on(‘input’,function(){
search($(this).val());
});

})

You’re missing client id.

Okay, im a little confused, i have my API Key,

But which one of the codes.

jQuery

$.ajax({
type: ‘GET’,
url: ‘https://api.twitch.tv/kraken/channels/twitch’,
headers: {
‘Client-ID’: ‘axjhfp777tflhy0yjb5sftsil’
},
success: function(data) {
console.log(data);
}
});
cURL
curl -i -H ‘Accept: application/vnd.twitchtv.v3+json’\
-H ‘Client-ID: axjhfp777tflhy0yjb5sftsil’\
https://api.twitch.tv/kraken/channels/twitch
PHP

<?php $channelsApi = 'https://api.twitch.tv/kraken/channels/'; $channelName = 'twitch'; $clientId = 'axjhfp777tflhy0yjb5sftsil'; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array( 'Client-ID: ' . $clientId ), CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $channelsApi . $channelName )); $response = curl_exec($ch); curl_close($ch); ?>

And where do i put the code???

The easiest way is

var url="https://api.twitch.tv/kraken/streams/"+name+"?client_id=your_client_id";

The Client-ID in the code above isn’t valid. It was used for illustration purposes in the v3 documentation. You’ll need to register a developer application and get your own Client-ID as shown in the Using the Twitch API documentation.

@DallasNChains

Yeah i copied the original streamid from the actual template.
I have my code i just had no idea where in the code above to put it

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