Client ID Update - Updating old plugin - Help

With your code i got this error first.

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

i just added it again and now my site isnt loading but im still able to access the backend of WP.

when i did it manually i got the error on line 16.

will that’s weird for me I tried it and it worked perfectly and I tried one of your codes and I get an error I tried on fresh code and made the change and it worked also but without my changes to the website then went back to my code with the changes I needed

you can check it here : www.arabictwitch.com

it will take a lot of time loading because the plugin isn’t that great and I need another one but couldn’t find any plugin that will do what I need like this one

So i did everything by hand again.

<?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 = 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 = $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"];
  	$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 = $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;
}

}
?>

Now i have some streams poping up on the home page but shows as offline instead of online. and i get this error as well

Warning: file_get_contents(https://api.twitch.tv/kraken/streams/?channel=the_aaron,mega64podcast): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/content/a2pnexwpnas03_data03/96/3342496/html/wp-content/plugins/TwitchWP/inc/Twitch.php on line 17

Im really trying to understand this. Nice site btw.
http://www.dragonslive.online

1 Like

thank you

and I was monitoring your website from yesterday and saw a lot of errors but haven’t seen any streams pop up

also do you use your own CLIENT-ID ? or the one you past with the code above ? because this one was in the twitch post to show how do you use it

update : I see that the streams pop on the main page not on the who’s live page

You know what. Its always the simple things that mess it all up. Aparently i copy and pasted so many times that i thought that was my client id.

Thank you so much my friend. were back in business

you’re welcome my friend glad it all worked out in the end

Hello,

I’d like to display some Informations about the Stream on Website.

With the Code down below it display the Name of the Streamer.

But when i use echo $result[“game”]; or echo $result[“viewers”]; nothing is displayed.

What is required to show this Informations too?

<?php

$url = “https://api.twitch.tv/kraken/users/rockstargames?client_id=xxx”;

$result = file_get_contents($url);
$result = json_decode($result, true);
echo $result[“display_name”];
?>

If you echo $result before doing json_decode is anything returned?

Thanks for your answer. After some tryings i’ve detect the failure. When the Url was https://api.twitch.tv/kraken/channels/rockstargames?client_id=xxx
instead of
https://api.twitch.tv/kraken/users/rockstargames?client_id=xxx
it works now and show the Informations :slight_smile:

Hi all,

I just copy all the code of @Tharmadawe on wordpress pluging “twitch status”. Copy on twitch-status.php but when i update the file, wordpress say me “this plugin have not a correct header”. The plugin desapear of wp-admin, and only can delete the folder in ftp for can install again…

HELP!

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