Livestream online/offline status

268 views
Skip to first unread message

Class M Gamer

unread,
May 1, 2012, 2:59:37 AM5/1/12
to Justin.tv API Developers
So I have a gaming community website that is looking to list a bunch
of streams.
But I'd like to show the online/offline status of each stream before
they click on it.

I was given this code:


<?php
header('content-type: image/png');

$stream = "username";

$json_file = @file_get_contents("http://api.justin.tv/api/stream/
list.json?channel={$stream}", 0, null, null);
$json_array = json_decode($json_file, true);

if ($json_array[0]['name'] == "live_user_{$stream}") {
echo file_get_contents("link_to_online_image");
}else{
echo file_get_contents("link_to_offline_image");
}

?>


But, I can not get it to work for the life of me. I changed username
to my username, and inserted the online/offline links. Help is
appreciated.

Ryan Cole

unread,
May 9, 2012, 3:22:20 PM5/9/12
to justintv-ap...@googlegroups.com
What is not working? If you point your browser to that URL, you receive the JSON.


Ryan

Class M Gamer

unread,
May 11, 2012, 1:16:31 PM5/11/12
to Justin.tv API Developers
The online/offline image doesn't appear at all. In fact, none of it
appears. It ends up being an empty box on the website.

On May 9, 3:22 pm, Ryan Cole <r...@rycole.com> wrote:
> What is not working? If you point your browser to that URL, you receive the
> JSON.
>
> For example:  http://api.justin.tv/api/stream/list.json?channel=tsm_theoddone
>
> Ryan
>
>
>
>
>
>
>
> On Tuesday, May 1, 2012 1:59:37 AM UTC-5, Class M Gamer wrote:
>
> > So I have a gaming community website that is looking to list a bunch
> > of streams.
> > But I'd like to show the online/offline status of each stream before
> > they click on it.
>
> > I was given this code:
>
> > <?php
> >     header('content-type: image/png');
>
> >     $stream = "username";
>
> >     $json_file = @file_get_contents("http://api.justin.tv/api/stream/
> > list.json?channel={$stream}<http://api.justin.tv/api/stream/list.json?channel=%7B$stream%7D>",

Devon H. O'Dell

unread,
May 11, 2012, 1:25:00 PM5/11/12
to justintv-ap...@googlegroups.com
Are you

2012/5/1 Class M Gamer <class...@gmail.com>:
> So I have a gaming community website that is looking to list a bunch
> of streams.
> But I'd like to show the online/offline status of each stream before
> they click on it.
>
> I was given this code:
>
>
> <?php
>    header('content-type: image/png');
>
>    $stream = "username";
>
>    $json_file = @file_get_contents("http://api.justin.tv/api/stream/
> list.json?channel={$stream}", 0, null, null);
>    $json_array = json_decode($json_file, true);
>
>    if ($json_array[0]['name'] == "live_user_{$stream}") {
>        echo file_get_contents("link_to_online_image");
>    }else{
>        echo file_get_contents("link_to_offline_image");
>    }

Is this literally the code you are using? If not, what do
"link_to_online_image" and "link_to_offline_image" signify? If it is,
these are not probably not existing files and do not identify a valid
PHP stream resource, either. You should look at your error log.

--dho

Class M Gamer

unread,
May 11, 2012, 5:43:41 PM5/11/12
to Justin.tv API Developers
It isn't literally what I used. I changed "username" to the JTV
username...and changed the link to offline/online images to actual
images.

On May 11, 1:25 pm, "Devon H. O'Dell" <devon.od...@gmail.com> wrote:
> Are you
>
> 2012/5/1 Class M Gamer <classmga...@gmail.com>:

Devon H. O'Dell

unread,
May 11, 2012, 6:51:59 PM5/11/12
to justintv-ap...@googlegroups.com
2012/5/11 Class M Gamer <class...@gmail.com>:
> It isn't literally what I used. I changed "username" to the JTV
> username...and changed the link to offline/online images to actual
> images.

Without any information about PHP errors that you are receiving, it is
impossible to provide you with any further information. I would
suggest visiting that page directly. If you get "This image contains
errors", try viewing the source of the page. There may be a PHP error
message. Otherwise, please check your server error log files to
determine what errors you are encountering.

Just as a tip, it's probably more efficient for you to make the source
attribute a link to the image, conditional on the online status of
whoever it is you are querying, instead of serving it through a
script.

--dho
Reply all
Reply to author
Forward
0 new messages