Twitch API to Show List of Streamers

So what I’m trying to do here is create a page to display a list of specific users and use the api to pull information to create links and point it to an embedded iframe.

<?php

/* 
The channels
*/  

$channels = array('everadiolive', 'djyumene', 'mrblades', "themittanidotcom", "daopa") ;

/* 
The part that does stuff
*/

$callAPI = implode(",",$channels);
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$dataArray = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams?channel=' . $callAPI, false), true);

foreach($dataArray['streams'] as $mydata){

    if($mydata['streams'] == null or $mydata['streams'] == ""){
        $name      = $mydata['channel']['display_name'];    

        echo "<a href='http://www.twitch.tv/" .$name. "/embed' target='tbox'><img src='http://streambadge.com/twitch/" .$name. ".png'></a>";
}

?>

This works, however there’s some issues that I’m having. It’s only showing the streams that are online (I want it to show all that are specified on the first line).

I also am seeing an issue to get more than 3 streams to show up. In this I have 4 streams listed, and the 4th one was active (at the time of this post) however it was ignored, where the 3rd stream that was running did show.

The first two were both offline, where it should have shown an offline graphic, there was nothing, so it’s not displaying unless the stream is offline.

I thought that I had this correct but seems I’m missing something here. So I’m hoping someone can help me here.

Thanks!


Source: json

Leave a Reply