Guest User

TwitchTV API call

a guest
Feb 28th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.     $stream_list = "TobiWanDota,xancara,jd_epi,dendi";
  3.    
  4.     $mycurl = curl_init();
  5.    
  6.     curl_setopt ($mycurl, CURLOPT_HEADER, 0);
  7.     curl_setopt ($mycurl, CURLOPT_RETURNTRANSFER, 1);
  8.    
  9.     //Build the URL
  10.     $url = "http://api.justin.tv/api/stream/list.json?channel=" . $stream_list;
  11.     curl_setopt ($mycurl, CURLOPT_URL, $url);
  12.    
  13.     $web_response =  curl_exec($mycurl);
  14.    
  15.     $results = json_decode($web_response);
  16.     $streamnum = 1;
  17.    
  18.     foreach($results as $s) {
  19.      echo "<div id=\"stream\">";
  20.      echo "<div id=\"user\">#$streamnum " . $s->channel->login;
  21.      echo "<div id=\"viewers\"> " . $s->channel_count . " viewers </div></div>\n<br />";
  22.      echo "<div id=\"title\">" . $s->title . "</div></td>\n<br />";
  23.      echo "<a target=\"_parent\" href=\"http://www.abyssgaming.us/livestream#" . $s->channel->login . "\">";
  24.      echo "<div id=\"screen\"><img src=\"" . $s->channel->screen_cap_url_medium . "\"></img></div>\n</a>";
  25.      echo "</div>";
  26.      $streamnum++;
  27.     }
  28.    
  29.     if (count($results) > 0)   { echo ''; }
  30.     else echo "<div id=\"offline\"><h1>Sorry, all of our streams are offline. Check out <a href=\"http://www.twitch.tv\">twitch</a> directly.</h1></div>";
  31.     ?>
Advertisement
Add Comment
Please, Sign In to add comment