Client ID Update - Updating old plugin - Help

So i am trying to update a plugin that is not supported by the author. I have bought a license to this plugin and have every right to change it. I am attempting to get the Client ID into the header of the php. Now i will admit i am a amateur at php and am just learning my self. Do i need to change more then just the header in the php code?

Here is what i have done

(client id php that twitch say to add) <?php
$channelsApi = ‘https://api.twitch.tv/kraken/channels/’;
$channelName = ‘twitch’;
$clientId = ‘clientid’;
$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);

class Twitch {
(start of old orginal code)

> public function getApiUri($type) {
  $apiUrl = "https://api.twitch.tv/kraken";
  $apiCalls = array(
  	"streams" => $apiUrl."/streams/",
  	"search" => $apiUrl."/search/",
  	"channel" => $apiUrl."/channels/",
  	"user" => $apiUrl."/user/",
  	"teams" => $apiUrl."/teams/",
  	"games" => $apiUrl."/games/top",
  	"search" => $APIURL."/search/"
  );
  return $apiCalls[$type];

}

public function getFeatured($game) {
$s = file_get_contents($this->getApiUri(“streams”).“?game=”.urlencode($game).“&limit=1&offset=0”);
$activeStreams = json_decode($s, true);
$streams = $activeStreams[“streams”];
foreach($streams as $stream) {
return $stream[“channel”][“name”];
}
}

public function getGames($amt) {
$s = file_get_contents($this->getApiUri(“games”).“?limit=$amt&offset=0”);
$activeGames = json_decode($s, true);
$games = $activeGames[“top”];
return $games;
}

public function getStreams($game, $page, $limit, $dopg) {
$offset = ($page-1)*$limit;
$total = floor($activeStreams[“_total”]/$limit);

  //Pagination
  $nextPage = $page+1;
  $paginate = "";
  if($page>1) {
  	$prevPage = $page-1;
  	$pageinate .= "<a href='?game=$game&pg=$prevPage'>< Previous Page</a>";
  }
  $pageinate .= "<a href='?game=$game&pg=$nextPage'>Next Page ></a>";		
  //Streams
  $s = file_get_contents($this->getApiUri("streams")."?game=".urlencode($game)."&limit=$limit&offset=$offset");
  $activeStreams = json_decode($s, true);
  $streams = $activeStreams["streams"];
  $final = "";
  foreach($streams as $stream) {
  	$imgsm = $stream["preview"]["small"];
  	$imgmed = $stream["preview"]["medium"];
  	$viewers = $stream["viewers"];
  	$channel = $stream["channel"];
  	$status = substr($channel["status"],0,40)."[...]";
  	$twitchName = $channel["name"];
  	$twitchDisplay = $channel["display_name"];
  	$twitchLink = $channel["url"];
  	$final .= "<a class=\"stream-item\" href=\"?channel=$twitchName\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\">$viewers viewers</span></a>";
  }
  if($dopg) {
  	$final .="<div class='stream-pagination'>".$pageinate."</div>";
  }
  return $final;

}

public function getUserStreams2($channels, $showOffline) {
//Pull Stream Data
$stream = file_get_contents($this->getApiUri(“streams”).“?channel=”.$channels);
$streamData = json_decode($stream, true);

  $online = array();
  $channelArray = explode(",", $channels);
  if($streamData["_total"] > 0) {
  	foreach($streamData["streams"] as $key=>$value){
  		$name = strtolower($value["channel"]["name"]);
  		//Set Channel to Online
  		$online[$name]["stream"] = $value;
  	}
  }
  foreach ($channelArray as $channel) {
  	$oc = $online[$channel];
  	if($oc) {
  	$imgsm = $oc["stream"]["preview"]["small"];
  	$imgmed = $oc["stream"]["preview"]["medium"];
  	$viewers = $oc["stream"]["viewers"];
  	$ch = $oc["stream"]["channel"];
  	$status = substr($ch["status"],0,40)."[...]";
  	$twitchName = $ch["name"];
  	$twitchDisplay = $ch["display_name"];
  	$twitchLink = $ch["url"];
  	//$final.=json_encode($oc);
  	$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers</span></a>";
  	} else {
  		if($showOffline=="true") {
  			$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"http://static-cdn.jtvnw.net/ttv-static/404_preview-320x180.jpg\"><span class=\"name\">$channel's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> Offline</span></a>";
  		}
  	}
  }
  //return json_encode($channelArray);
  return $final;

}

public function getUserStreams($channels, $showOffline) {
//Streams
$final = “”;
$offline = array();
foreach($channels as $channel) {
$stream = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($stream, true);

  	if(is_null($streamData["stream"])) {
  		array_push($offline, $channel);
  		continue;
  	} else {
  		$imgsm = $streamData["stream"]["preview"]["small"];
  		$imgmed = $streamData["stream"]["preview"]["medium"];
  		$viewers = $streamData["stream"]["viewers"];
  		$ch = $streamData["stream"]["channel"];
  		$status = substr($ch["status"],0,40)."[...]";
  		$twitchName = $ch["name"];
  		$twitchDisplay = $ch["display_name"];
  		$twitchLink = $ch["url"];
  		$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers</span></a>";
  	}
  }
  if($showOffline=="true") {
  	foreach($offline as $channel) {
  		$cdata = file_get_contents($this->getApiUri("channel").$channel);
  		$ch = json_decode($cdata, true);
  		$status = substr($ch["status"],0,40)."[...]";
  		$twitchName = $ch["name"];
  		$twitchDisplay = $ch["display_name"];
  		$twitchLink = $ch["url"];
  		$imgmed = $ch["logo"];
  		$followers = $ch["followers"];
  		$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><div class='offline-streamer'><img src=\"$imgmed\"></div><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> $followers followers</span></a>";
  	}
  }
  return $final;

}

public function getChannel($channel) {
$c = file_get_contents($this->getApiUri(“channel”).$channel);
$channelData = json_decode($c, true);
return $channelData;
}

public function getFollowers($channel) {
$f = file_get_contents($this->getApiUri(“channel”).$channel.“/follows”);
$followData = json_decode($f, true);
return $followData[“_total”];
}
public function isLive($channel) {
$s = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($s, true);
if(is_null($streamData[“stream”])) {
return false;
} else {
return true;
}
return true;
}
public function getChannelStream($channel) {
$s = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($s, true);
return $streamData;
}

}
?>
Any help would be apreciated. My websites depend on this. Thank you!

You can just append ?client_id=clientID to the URL instead

So the top half is what Twitch states to put in the header.

This is what the code looked like before i added it. So based off your suggestions, is that still the route to go?

<?php public function getApiUri($type) { $apiUrl = "https://api.twitch.tv/kraken"; $apiCalls = array( "streams" => $apiUrl."/streams/", "search" => $apiUrl."/search/", "channel" => $apiUrl."/channels/", "user" => $apiUrl."/user/", "teams" => $apiUrl."/teams/", "games" => $apiUrl."/games/top", "search" => $APIURL."/search/" ); return $apiCalls[$type]; }

public function getFeatured($game) {
$s = file_get_contents($this->getApiUri(“streams”).“?game=”.urlencode($game).“&limit=1&offset=0”);
$activeStreams = json_decode($s, true);
$streams = $activeStreams[“streams”];
foreach($streams as $stream) {
return $stream[“channel”][“name”];
}
}

public function getGames($amt) {
$s = file_get_contents($this->getApiUri(“games”).“?limit=$amt&offset=0”);
$activeGames = json_decode($s, true);
$games = $activeGames[“top”];
return $games;
}

public function getStreams($game, $page, $limit, $dopg) {
$offset = ($page-1)*$limit;
$total = floor($activeStreams[“_total”]/$limit);

  //Pagination
  $nextPage = $page+1;
  $paginate = "";
  if($page>1) {
  	$prevPage = $page-1;
  	$pageinate .= "<a href='?game=$game&pg=$prevPage'>< Previous Page</a>";
  }
  $pageinate .= "<a href='?game=$game&pg=$nextPage'>Next Page ></a>";		
  //Streams
  $s = file_get_contents($this->getApiUri("streams")."?game=".urlencode($game)."&limit=$limit&offset=$offset");
  $activeStreams = json_decode($s, true);
  $streams = $activeStreams["streams"];
  $final = "";
  foreach($streams as $stream) {
  	$imgsm = $stream["preview"]["small"];
  	$imgmed = $stream["preview"]["medium"];
  	$viewers = $stream["viewers"];
  	$channel = $stream["channel"];
  	$status = substr($channel["status"],0,40)."[...]";
  	$twitchName = $channel["name"];
  	$twitchDisplay = $channel["display_name"];
  	$twitchLink = $channel["url"];
  	$final .= "<a class=\"stream-item\" href=\"?channel=$twitchName\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\">$viewers viewers</span></a>";
  }
  if($dopg) {
  	$final .="<div class='stream-pagination'>".$pageinate."</div>";
  }
  return $final;

}

public function getUserStreams2($channels, $showOffline) {
//Pull Stream Data
$stream = file_get_contents($this->getApiUri(“streams”).“?channel=”.$channels);
$streamData = json_decode($stream, true);

  $online = array();
  $channelArray = explode(",", $channels);
  if($streamData["_total"] > 0) {
  	foreach($streamData["streams"] as $key=>$value){
  		$name = strtolower($value["channel"]["name"]);
  		//Set Channel to Online
  		$online[$name]["stream"] = $value;
  	}
  }
  foreach ($channelArray as $channel) {
  	$oc = $online[$channel];
  	if($oc) {
  	$imgsm = $oc["stream"]["preview"]["small"];
  	$imgmed = $oc["stream"]["preview"]["medium"];
  	$viewers = $oc["stream"]["viewers"];
  	$ch = $oc["stream"]["channel"];
  	$status = substr($ch["status"],0,40)."[...]";
  	$twitchName = $ch["name"];
  	$twitchDisplay = $ch["display_name"];
  	$twitchLink = $ch["url"];
  	//$final.=json_encode($oc);
  	$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers</span></a>";
  	} else {
  		if($showOffline=="true") {
  			$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"http://static-cdn.jtvnw.net/ttv-static/404_preview-320x180.jpg\"><span class=\"name\">$channel's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> Offline</span></a>";
  		}
  	}
  }
  //return json_encode($channelArray);
  return $final;

}

public function getUserStreams($channels, $showOffline) {
//Streams
$final = “”;
$offline = array();
foreach($channels as $channel) {
$stream = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($stream, true);

  	if(is_null($streamData["stream"])) {
  		array_push($offline, $channel);
  		continue;
  	} else {
  		$imgsm = $streamData["stream"]["preview"]["small"];
  		$imgmed = $streamData["stream"]["preview"]["medium"];
  		$viewers = $streamData["stream"]["viewers"];
  		$ch = $streamData["stream"]["channel"];
  		$status = substr($ch["status"],0,40)."[...]";
  		$twitchName = $ch["name"];
  		$twitchDisplay = $ch["display_name"];
  		$twitchLink = $ch["url"];
  		$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers</span></a>";
  	}
  }
  if($showOffline=="true") {
  	foreach($offline as $channel) {
  		$cdata = file_get_contents($this->getApiUri("channel").$channel);
  		$ch = json_decode($cdata, true);
  		$status = substr($ch["status"],0,40)."[...]";
  		$twitchName = $ch["name"];
  		$twitchDisplay = $ch["display_name"];
  		$twitchLink = $ch["url"];
  		$imgmed = $ch["logo"];
  		$followers = $ch["followers"];
  		$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><div class='offline-streamer'><img src=\"$imgmed\"></div><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> $followers followers</span></a>";
  	}
  }
  return $final;

}

public function getChannel($channel) {
$c = file_get_contents($this->getApiUri(“channel”).$channel);
$channelData = json_decode($c, true);
return $channelData;
}

public function getFollowers($channel) {
$f = file_get_contents($this->getApiUri(“channel”).$channel.“/follows”);
$followData = json_decode($f, true);
return $followData[“_total”];
}
public function isLive($channel) {
$s = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($s, true);
if(is_null($streamData[“stream”])) {
return false;
} else {
return true;
}
return true;
}
public function getChannelStream($channel) {
$s = file_get_contents($this->getApiUri(“streams”).$channel);
$streamData = json_decode($s, true);
return $streamData;
}

}
?>

Ive taken the last suggestion and applyed it but the result is the same as before. Instead of adding whole string of php i added the client id into the URL.

<?php

class Twitch {

public function getApiUri($type) {
$apiUrl =‘https://api.twitch.tv/kraken/?client_id=clientid’;
$apiCalls = array(
“streams” => $apiUrl.“/streams/”,
“search” => $apiUrl.“/search/”,
“channel” => $apiUrl.“/channels/”,
“user” => $apiUrl.“/user/”,
“teams” => $apiUrl.“/teams/”,
“games” => $apiUrl.“/games/top”,
“search” => $APIURL.“/search/”
);
return $apiCalls[$type];
}

I dont get any line errors on the site, only this

Warning: file_get_contents(https://api.twitch.tv/kraken/channels/?client_id=clientid/streams/?

you can view my site where i am trying to get this plugin to work once again.
http://www.dragonslive.online/who-is-live/

Sorry, that needs to come last in the URL

So it would be either (?client_id= because it’s the first/only variable)

https://api.twitch.tv/kraken/streams?client_id=CLIENTID

or (&client_id= because it comes after another variable)

https://api.twitch.tv/kraken/streams?channel=channel1,channel2,channel3&client_id=CLIENTID

Hmm. Well i’m sure you aware it’s not the best written code. So this is not really a practice I would recommend. But I think it will be the easiest solution for you.

If you search for:

file_get_contents(

replace with:

$this->getContents(

And then if you place this code in the same file and within the same class, it should work.

public function getContents($url) {
    $clientID = 'YOUR_CLIENT_ID';
    
    $opts = array(
      'http' => array(
        'method' => "GET",
        'header' => "Client-ID: $clientID"
      )
    );

    $context = stream_context_create($opts);

    return file_get_contents($url, false, $context);
}
2 Likes

@kaugesaar has a working example.

You could also update getApiUrl to append the client ID to the URL and then update all of your other methods to replace the ? with an &. It’d look something like this:

public function getApiUri($type){
   ...
   return $apiCalls[$type] . "?client_id=XXXXX";
}

public function getFeatured($game){
   $s = file_get_contents($this->getApiUri("streams")."&game=" ...
   ...
}

It may be hard to spot, but notice that the question mark in getFeatured was replaced with an ampersand. That’s the important part. Otherwise, you end up with an incorrect URL like: /streams?client_id=XXXX?game=... The client_id can be anywhere in the URL.

Thank you so much for your help. Those are some great solutions and im actively trying them out right now. I fully understand if this plugin is a bit messy but it worked so well before the crackdown and it is the only plugin i have found that does what i need it to do on my site. That’s why i am so eager to bring it back to life. Also again, this all could be do to my in experience here as well. So @kaugesaar i have applied your solution and this is what i still get.

Now, i changed file_get_contents in that string you gave and this is the result after.

Fatal error: Allowed memory size of 268435456bytes exhausted (tried to allocate 64 bytes) in /home/content(blah blah)/plugins/twitchwp/inc/twitch.php on line 15

Here is how i placed it in the code, right under the class:

<?php

class Twitch {

public function getContents($url) {
$clientID = ‘axjhfp777tflhy0yjb5sftsil’;

$opts = array(
  'http' => array(
    'method' => "GET",
    'header' => "Client-ID: $clientID"
  )
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);

}

public function getApiUri($type) {
$apiUrl = “https://api.twitch.tv/kraken”;
$apiCalls = array(
“streams” => $apiUrl.“/streams/”,
“search” => $apiUrl.“/search/”,
“channel” => $apiUrl.“/channels/”,
“user” => $apiUrl.“/user/”,
“teams” => $apiUrl.“/teams/”,
“games” => $apiUrl.“/games/top”,
“search” => $APIURL.“/search/”
);
return $apiCalls[$type];
}

I may not have explained this but this is a Worldpress plugin, So im starting to think that i need to change other things other then just on the main php file that calls to the api. Being that this uses short codes within WP pages i might be calling on this wrong to get these responses.

for me the solution kaugesaar provided worked and the plugin is now working like it was before

I applied it yesterday and you will need to change file_get_contents( to $this->getContents( about 11 times in the file then place the code he provided in the same class

check that you changed it as I said in every place in the code which will be around 11 times

and till us did it work or not after that

@Tharmadawe Tharmadawe

Thats what i just have done but now im getting this through out my site.

Parse error: syntax error, unexpected ‘public’ (T_PUBLIC) in /home/content/a2pnexwpnas03_data03/96/3342496/html/wp-content/plugins/TwitchWP/inc/Twitch.php on line 3

And this is the code now.

<?php class Twitch { public function getContents($url) { $clientID = 'axjhfp777tflhy0yjb5sftsil'; $opts = array( 'http' => array( 'method' => "GET", 'header' => "Client-ID: $clientID" ) ); $context = stream_context_create($opts); return file_get_contents($url, false, $context); } public function getApiUri($type) { $apiUrl = "https://api.twitch.tv/kraken"; $apiCalls = array( "streams" => $apiUrl."/streams/", "search" => $apiUrl."/search/", "channel" => $apiUrl."/channels/", "user" => $apiUrl."/user/", "teams" => $apiUrl."/teams/", "games" => $apiUrl."/games/top", "search" => $APIURL."/search/" ); return $apiCalls[$type]; } public function getFeatured($game) { $s = $this->getContents(($this->getApiUri("streams")."?game=".urlencode($game)."&limit=1&offset=0"); $activeStreams = json_decode($s, true); $streams = $activeStreams["streams"]; foreach($streams as $stream) { return $stream["channel"]["name"]; } } public function getGames($amt) { $s = $this->getContents(($this->getApiUri("games")."?limit=$amt&offset=0"); $activeGames = json_decode($s, true); $games = $activeGames["top"]; return $games; } public function getStreams($game, $page, $limit, $dopg) { $offset = ($page-1)*$limit; $total = floor($activeStreams["_total"]/$limit); //Pagination $nextPage = $page+1; $paginate = ""; if($page>1) { $prevPage = $page-1; $pageinate .= "< Previous Page"; } $pageinate .= "Next Page >"; //Streams $s = $this->getContents(($this->getApiUri("streams")."?game=".urlencode($game)."&limit=$limit&offset=$offset"); $activeStreams = json_decode($s, true); $streams = $activeStreams["streams"]; $final = ""; foreach($streams as $stream) { $imgsm = $stream["preview"]["small"]; $imgmed = $stream["preview"]["medium"]; $viewers = $stream["viewers"]; $channel = $stream["channel"]; $status = substr($channel["status"],0,40)."[...]"; $twitchName = $channel["name"]; $twitchDisplay = $channel["display_name"]; $twitchLink = $channel["url"]; $final .= "$twitchDisplay's Stream$viewers viewers"; } if($dopg) { $final .="
".$pageinate."
"; } return $final; } public function getUserStreams2($channels, $showOffline) { //Pull Stream Data $stream = $this->getContents(($this->getApiUri("streams")."?channel=".$channels); $streamData = json_decode($stream, true); $online = array(); $channelArray = explode(",", $channels); if($streamData["_total"] > 0) { foreach($streamData["streams"] as $key=>$value){ $name = strtolower($value["channel"]["name"]); //Set Channel to Online $online[$name]["stream"] = $value; } } foreach ($channelArray as $channel) { $oc = $online[$channel]; if($oc) { $imgsm = $oc["stream"]["preview"]["small"]; $imgmed = $oc["stream"]["preview"]["medium"]; $viewers = $oc["stream"]["viewers"]; $ch = $oc["stream"]["channel"]; $status = substr($ch["status"],0,40)."[...]"; $twitchName = $ch["name"]; $twitchDisplay = $ch["display_name"]; $twitchLink = $ch["url"]; //$final.=json_encode($oc); $final .= "$twitchDisplay's Stream $viewers viewers"; } else { if($showOffline=="true") { $final .= "$channel's Stream Offline"; } } } //return json_encode($channelArray); return $final; } public function getUserStreams($channels, $showOffline) { //Streams $final = ""; $offline = array(); foreach($channels as $channel) { $stream = $this->getContents(($this->getApiUri("streams").$channel); $streamData = json_decode($stream, true); if(is_null($streamData["stream"])) { array_push($offline, $channel); continue; } else { $imgsm = $streamData["stream"]["preview"]["small"]; $imgmed = $streamData["stream"]["preview"]["medium"]; $viewers = $streamData["stream"]["viewers"]; $ch = $streamData["stream"]["channel"]; $status = substr($ch["status"],0,40)."[...]"; $twitchName = $ch["name"]; $twitchDisplay = $ch["display_name"]; $twitchLink = $ch["url"]; $final .= "$twitchDisplay's Stream $viewers viewers"; } } if($showOffline=="true") { foreach($offline as $channel) { $cdata = $this->getContents(($this->getApiUri("channel").$channel); $ch = json_decode($cdata, true); $status = substr($ch["status"],0,40)."[...]"; $twitchName = $ch["name"]; $twitchDisplay = $ch["display_name"]; $twitchLink = $ch["url"]; $imgmed = $ch["logo"]; $followers = $ch["followers"]; $final .= "
$twitchDisplay's Stream $followers followers
"; } } return $final; } public function getChannel($channel) { $c = $this->getContents(($this->getApiUri("channel").$channel); $channelData = json_decode($c, true); return $channelData; } public function getFollowers($channel) { $f = $this->getContents(($this->getApiUri("channel").$channel."/follows"); $followData = json_decode($f, true); return $followData["_total"]; } public function isLive($channel) { $s = $this->getContents(($this->getApiUri("streams").$channel); $streamData = json_decode($s, true); if(is_null($streamData["stream"])) { return false; } else { return true; } return true; } public function getChannelStream($channel) { $s = $this->getContents(($this->getApiUri("streams").$channel); $streamData = json_decode($s, true); return $streamData; } } ?>

I will post my code for you and give it a go

( I have changed a lot in the code first when I installed it so it would fit my needs, so give it a go and see if it would work or no then I might edit the original one so it wouldn’t show the changes that I made on your website )

I tried to post the full code but it wouldn’t let me I get an error saying new users cant post more than one image !!

Worked perfectly thank you so much!

Dont post it as a image, just copy paste. works for me.

yeah I copy pasted it I will give it another go

// start of code
<?php

class Twitch {

public function getContents($url) {
    $clientID = 'YOUR Client-ID HERE';
    
    $opts = array(
      'http' => array(
        'method' => "GET",
        'header' => "Client-ID: $clientID"
      )
    );

    $context = stream_context_create($opts);

    return file_get_contents($url, false, $context);
}

public function getApiUri($type) {
$apiUrl = "https://api.twitch.tv/kraken";
$apiCalls = array(
"streams" => $apiUrl."/streams/",
"search" => $apiUrl."/search/",
"channel" => $apiUrl."/channels/",
"user" => $apiUrl."/user/",
"teams" => $apiUrl."/teams/",
"games" => $apiUrl."/games/top",
"search" => $APIURL."/search/"
);
return $apiCalls[$type];
}

public function getFeatured($game) {
$s = $this->getContents($this->getApiUri("streams")."?game=".urlencode($game)."&limit=1&offset=0");
$activeStreams = json_decode($s, true);
$streams = $activeStreams["streams"];
foreach($streams as $stream) {
return $stream["channel"]["name"];
}
}

public function getGames($amt) {
$s = $this->getContents($this->getApiUri("games")."?limit=$amt&offset=0");
$activeGames = json_decode($s, true);
$games = $activeGames["top"];
return $games;
}

public function getStreams($game, $page, $limit, $dopg) {
$offset = ($page-1)*$limit;
$total = floor($activeStreams["_total"]/$limit);

//Pagination
$nextPage = $page+1;
$paginate = "";
if($page>1) {
$prevPage = $page-1;
$pageinate .= "<a href='?game=$game&pg=$prevPage'>< Previous Page</a>";
}
$pageinate .= "<a href='?game=$game&pg=$nextPage'>Next Page ></a>";

//Streams
$s = $this->getContents($this->getApiUri("streams")."?game=".urlencode($game)."&limit=$limit&offset=$offset");
$activeStreams = json_decode($s, true);
$streams = $activeStreams["streams"];
$final = "";
foreach($streams as $stream) {
$imgsm = $stream["preview"]["small"];
$imgmed = $stream["preview"]["medium"];
$viewers = $stream["viewers"];
$channel = $stream["channel"];
$status = substr($channel["status"],0,40)."[...]";
$twitchName = $channel["name"];
$twitchDisplay = $channel["display_name"];
$twitchLink = $channel["url"];

$final .= "<a class=\"stream-item\" href=\"?channel=$twitchName\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\">$viewers viewers</span></a>";
}
if($dopg) {
$final .="<div class='stream-pagination'>".$pageinate."</div>";
}
return $final;
}

public function getUserStreams2($channels, $showOffline) {
//Pull Stream Data
$stream = $this->getContents($this->getApiUri("streams")."?channel=".$channels);
$streamData = json_decode($stream, true);
$online = array();
$channelArray = explode(",", $channels);

if($streamData["_total"] > 0) {
foreach($streamData["streams"] as $key=>$value){
$name = strtolower($value["channel"]["name"]);

//Set Channel to Online
$online[$name]["stream"] = $value;

}
}

foreach ($channelArray as $channel) {

$oc = $online[$channel];
if($oc) {
$imgsm = $oc["stream"]["preview"]["small"];
$imgmed = $oc["stream"]["preview"]["medium"];
$viewers = $oc["stream"]["viewers"];
$status = substr($ch["status"],0,40)."[...]";
$ch = $oc["stream"]["channel"];
$imgmeddd = $ch["logo"];
$followers = $ch["followers"];
$banner = $ch["video_banner"];
$twitchName = $ch["name"];
$twitchDisplay = $ch["display_name"];
$twitchLink = $ch["url"];
$game = $ch["game"];
//$final.=json_encode($oc);
if($showOffline=="false"){
$final .= "<a class=\"stream-item\" href=\"$twitchLink\" target=\"_blank\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers </span><span>Playing $game</span></a>";
}
} else if($showOffline=="true") {
$ccdata = $this->getContents($this->getApiUri("channel").$channel);
$chh = json_decode($ccdata, true);
$status = substr($chh["status"],0,40)."[...]";
$twitchName = $chh["name"];
$twitchDisplay = $chh["display_name"];
$twitchLink = $chh["url"];
$imgmed = $chh["logo"];
$followers = $chh["followers"];
$banner = $chh["video_banner"];
$game = $chh["game"];
$final .= "<a class=\"stream-item\" href=\"$twitchLink\" target=\"_blank\"><img src=\"$imgmed\"><span class=\"name\">$channel's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> Offline, $followers followers</span><span>Last Played $game</span></a>";
}
}
//return json_encode($channelArray);
return $final;
}

public function getUserStreams($channels, $showOffline) {
//Streams
$final = "";
$offline = array();
foreach($channels as $channel) {
$stream = $this->getContents($this->getApiUri("streams").$channel);
$streamData = json_decode($stream, true);

if(is_null($streamData["stream"])) {
array_push($offline, $channel);
continue;
} else {
$imgsm = $streamData["stream"]["preview"]["small"];
$imgmed = $streamData["stream"]["preview"]["medium"];
$viewers = $streamData["stream"]["viewers"];
$ch = $streamData["stream"]["channel"];
$status = substr($ch["status"],0,40)."[...]";
$twitchName = $ch["name"];
$twitchDisplay = $ch["display_name"];
$twitchLink = $ch["url"];
$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><img src=\"$imgmed\"><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='online-icon'></span> $viewers viewers</span></a>";
}
}

if($showOffline=="true") {
foreach($offline as $channel) {
$cdata = $this->getContents($this->getApiUri("channel").$channel);
$ch = json_decode($cdata, true);

$status = substr($ch["status"],0,40)."[...]";
$twitchName = $ch["name"];
$twitchDisplay = $ch["display_name"];
$twitchLink = $ch["url"];
$imgmed = $ch["logo"];
$followers = $ch["followers"];
$final .= "<a class=\"stream-item\" href=\"?channel=$channel\"><div class='offline-streamer'><img src=\"$imgmed\"></div><span class=\"name\">$twitchDisplay's Stream</span><span class=\"viewers\"><span class='offline-icon'></span> $followers followers</span></a>";
}
}

return $final;
}

public function getChannel($channel) {
$c = $this->getContents($this->getApiUri("channel").$channel);
$channelData = json_decode($c, true);
return $channelData;
}

public function getFollowers($channel) {
$f = $this->getContents($this->getApiUri("channel").$channel."/follows");
$followData = json_decode($f, true);
return $followData["_total"];
}
public function isLive($channel) {
$s = $this->getContents($this->getApiUri("streams").$channel);
$streamData = json_decode($s, true);
if(is_null($streamData["stream"])) {
return false;
} else {
return true;
}
return true;
}
public function getChannelStream($channel) {
$s = $this->getContents($this->getApiUri("streams").$channel);
$streamData = json_decode($s, true);
return $streamData;
}

}
?>

// END of CODE

it worked now give it a go and see if it will work or there is some of my changes need other changes on the other files I don’t remember if I changed the other files to make it work with my changes I will try to find the original file and make the API changes on it for you if this doesn’t work

Im getting the same unfortunate message that i keep getting since i made the changes the first time.

Parse error: syntax error, unexpected ‘public’ (T_PUBLIC) in /home/content/a2pnexwpnas03_data03/96/3342496/html/wp-content/plugins/TwitchWP/inc/Twitch.php on line 3

going to uninstall plugin and reinstall it so im working with a fresh copy and then paste it in again and see what happens.

Ok. Fresh install of the plugin, Updated the file we are working on. Added solutions and when through and changed all the get_file_contents to $this->getContents and same result. Still not pulling the list of streams i have listed within the shortcode.

Warning: file_get_contents(https://api.twitch.tv/kraken/streams/?channel=zedggaming,hazzy1998,asylix,fasick101,withguytv,thebigredt,starlitfoxx,porkmarshmallow,grindheadjim,bongwatermilkshake,incredicate,dragonsgetit,nacho_supreme,donnyboyelesief,bionicblue,911bige911,xpixeedustx,paladin_goo,banzhai,is3npai,ekkoniner,joshabrey,machete848,kylewilliams50,gustavogonz13,warwickknight,yt_azgaming,screaminrob,bloody_savior_,ghosttown201,tvsboh,onfire53,bigjmacht,tootmetoota,robofallgames,akashaheart,noobicus,l0rd_tyler,gstacks1,playinithard,lightnevaeh,stoopid8,gothicbeauty,zetaspartan21,almostgamingtv,arkhamalien,therealk1ll3r,nerdsauce,jomo_man,resin_x,jkinzzz209,willgasmic,bananatm_,80markus,jmitt,mysticangel09,lightningkilltv,csrtslammer,nixiethedragon,succeededcoma,hiimGinger,thyregodtv,saleman_89,mr_theranger,surfin989,lilstacks131,therealyodaiam,pvgunknowngreatest,fishstalker32,pfccounts,drax_420,ehhgreg,jayzedpc,AlfaSounds,roll4role,vynirian,korean666666jesus,ghstr3con,mushmouthgaming,zazelroyal,haroldonicus,microex in /home/content/a2pnexwpnas03_data03/96/3342496/html/wp-content/plugins/TwitchWP/inc/Twitch.php on line 16

From my point of view, line 16 is

$context = stream_context_create($opts);

did you apply the solution to the original code or fully replaced the code with my code ?

I’ve tried both ways.

both with the same error for the same line ?