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!