Help reviving an old script?

Just need a little bit help getting this to work… I’m a huge noob :frowning:

<title>Your Title Goes Here</title>
/* Mucked together by Matt_Thomas @
   Was created in response to:
   This will take the $channels array list of users, find the streamer in your list ($channels) with the most viewers, then
   display it's stream.  If none of the streamers are live, it will find the current twitch streamer with the most viewers instead.
   This can be modified easily to include any list of streamers.  You can also change the fall back to be a specific game. Enjoy!
   Shoutouts to Kevo and - Where I started from.
   matt AT mrthomas DOT org */

/* Old unsupported API for team members: - Might use this until kraken has team member listing, or until it changes */

$channels = array("fhaelin", "kittyplaysgames", "schyax", "cutenaomi", "cincinbear", "brialeigh", "juliehaze", "pallyberry"); /* For now, we use a manually set list of streamers */
$callAPI = implode(",",$channels); /* Clean our list for next step */
$dataArray = json_decode(@file_get_contents('' . $callAPI), true); /* Pull the data from for each streamer in our list */

/* The query could just add '&limit=1' since the API will return the streamers in order of highest viewers to lowest. This speeds things up.*/
/* $dataArray = json_decode(@file_get_contents('' . $callAPI . '&limit=1'), true); */

$max_viewers=0; /* Set a value to start stepping from */
$name='*** ERROR!!1! ***'; /* Set a value to name incase something goes wrong */

if ($dataArray['streams'] != null) { /* Make sure we get a response from the API */
    foreach($dataArray['streams'] as $mydata){ /* Build an array with online streamers from our list */
        if($mydata['_id'] != null){  /* Make sure the streamer has data in the API */
            $viewers = $mydata['viewers'];  /* Store value of viewers from API as $viewers */
            if ( $viewers > $max_viewers ) {  /* Should always be more than 0 at this point */
                $max_viewers = $viewers;   /* Set new nonzero value to be $max_viewers and loop 'foreach' until we have the highest viewer count */
                $name = $mydata['channel']['display_name'];  /* Store the display_name from API for user with highest viewer count */
else {
    /* None of the $channels I wanted are avaiable now, so fetch the most popular one */
    $backupArray = json_decode(@file_get_contents('' . $callAPI), true); 
    if ( $backupArray != null ) {
        foreach($backupArray['streams'] as $mydata){
            if($mydata['_id'] != null) {
                $name = $mydata['channel']['display_name'];
                $viewers = $mydata['viewers'];
            else {
                echo "Error in results from, cannot fetch a channel.";  /* API responded but not with expected data */
    else {
        echo "Error in results from, probably cannot connect to server."; /* API probably did not respond at all */
<h1> Streamer: <?php echo "$name" ?> </h1>

I added the iframe line as well as the client_id=XXXXXX in the kraken link. Originally it wouldnt pull the channel name but I got it to do that… now nothing happens when I click play on the iframe player :frowning: I’m thinking that the player is not associating itself with the code? I know absolutely nothing about code so any help would be appreciated!

EDIT: Got the code pasted

Try posting the code inside a pair of triple grave accents (`). Ex:

Alright! Thanks so much for that george :slight_smile:

        height="720" ...

$channel is undefined. I think you’re looking for $name.

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