Hi Everyone,
some time ago someone gave me a PHP script for my website to display a list of online Twitch channels. Now that script is not working anymore. Unfortunately i have no clue what to change to get it working again.
It would be great if someone can help me out here and tell me what to change for the new Twitch API.
This is what i got:
class TwitchConnector
{
public static function getStreamsFromTwitch($stream_list)
{
$mycurl = curl_init();
$url = "https://api.twitch.tv/kraken/streams?channel=" . $stream_list;
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
curl_setopt_array($mycurl, array(
CURLOPT_HTTPHEADER => array('Client-ID: '. $clientId),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url));
curl_setopt($mycurl, CURLOPT_URL, $url);
$web_response = curl_exec($mycurl);
$response = json_decode($web_response);
$streams = array();
if($response != null && !empty($response) && $response->streams != null) {
foreach ($response->streams as $stream) {
$streamObj = new Stream();
$streamObj->setViewerCount($stream->viewers);
$streamObj->setPreviewImage($stream->preview->medium);
$streamObj->setDisplayname($stream->channel->display_name);
$streamObj->setGame($stream->channel->game);
$streamObj->setCaster($stream->channel->name);
$streamObj->setDescription(htmlspecialchars($stream->channel->status));
$streams[] = $streamObj;
}
}
return $streams;
}
}
There also is a 2nd PHP File, which is providing the $stream_list
Thank you very much