Maybe you're interested About this site or in some of my Projects or Articles. You might even be interested About me or My Friends. If all else fails head back Home.

Morethanseven is where plays with the web

Example of the Yahoo Live Api

February 12th, 2008

Yahoo! Live launched recently along with a nice RESTful API. I’ve spoken before about the beauty of REST being in lowering the barrier to hacking and when I wanted a quick feature for Live it was simplicity itself to put together.

A few friends are using it far too much it seems, Ben has 7.6 hours and Si has already clocked up 15 hours. But for the most part I keep missing their no-doubt highly entertaining antics. One thing that Live misses I feel is a favourite users or previously viewed channels list. Basically I want to see which of my friends who use the service are broadcasting right now. Something like:

Yahoo! Live Online

The API request we’re interested in is the /channel/PERMALINK method. This lets us get information about whether the user is broadcasting at the moment.

<?php
$api = 'http://api.live.yahoo.com/api/v1/channel';
$friends = array(
  'garethr',
  'benward',
  'sijobling'
);
$statuses = array();
foreach ($friends as $friend) {
  $response = simplexml_load_file($api . '/' . $friend);
  $name = $response->name;
  if ($response->broadcast) {
    $status = 'live';
  } else {
    $status = 'offline';
  }
  $statuses["$name"] = $status;
}
function displaylist($array) {
  $output = '';
  if (count($array) >= 0) {
    $output .= '<ul>';
    foreach ($array as $key => $value) {
      $output .= "<li class=\"$value\">";
      $output .= "<a href=\"http://live.yahoo.com/$key\">";
      $output .= "$key</a>";
      $output .= "<span>$value</span></li>";
    }
    $output .= '</ul>';
  }
  return $output;
}
echo displaylist($statuses);
?>

I’ll add a few more people to my list when I discover other people using the service. If you have an account leave a comment. I’ve added a touch of javascript as well so as to avoid having to reload the page manually. This way I can loiter on my little aggregator until someone I know starts broadcasting and head over to Live for whatever Si has been spending 15 hours doing.

Popularity: 11%

Tagged , , ,

7 Responses to “Example of the Yahoo Live Api”

  1. The other thing that Live misses is the ability to work through firewalls. :(

  2. Oh, and if it’s throwing errors it’s probably because Yahoo! live is in maintenance and I didn’t build in any error checking as yet :-)

  3. 15 hours of pure, unadulterated screen staring. It’s marvellous what you can broadcast from an office!

  4. Oh cool! I’d been wondering if it was possible to check if someone was online or not only yesterday, and there’s the code for it. Thanks :)

  5. Yeah, I could have explained a little better actually. You can check whether someone is online by checking for the presence of the broadcast element in the response from /channel/PERMALINK

  6. [...] anyone to create their own live video channel, available to anyone who cares to watch. As has been pointed out before, there is plenty of scope to increase its potential for social networking. YLiveGroups is our [...]

  7. [...] servers. Generally speaking, it’s been quite well received. Not only have they opened up the API for developers to mess around with, but there has also been quite a large following in the DJ community with many DJ’s [...]

Leave a Reply