Jump to content

LF Help with twitch api and php stuff... x_x


  • Please log in to reply
2 replies to this topic

#1 GemGirl

GemGirl
  • Members
  • Posts: 12

Posted 13 May 2013 - 08:21 PM

Hi I'm really new to this php stuff... and I apologize for being so noob..

I have a gaming community... and I do all the site graphics html and etc etc... I want to surprise my community by being able to put their streams online and offline in a php script. however.. im very new to all this and I've tried researching many pages.. but I just can't for the life of me figure out how to make the .php file.. what parameters to change in the code... and also how to make it appear on the site....

This is the code i found though.. I cant figure out what to change in it for channel url.. So it'll show just a single person's channel..Do I need to copy and paste this code over and over in one file for every person's channel to show?

I also need to figure out what file to save it.. all I know is you put it on notepad.. do I save it as a .php?

And how to I make it even appear on my site? Do I just put embed url = url.php? as an object.. I'm sorry for the bother... I just really need help in this.

Also I use enjin.. yes they do allow me to upload files there and yes those files can be directed to the site. (I think you need that for PHP)

<?php
$channel = "CHANNELNAME"; // lowercase or the shit gonna be serius
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channel}", 0, null, null); // care the link i have space between http and api cause i must have 5 posts to post links blah blah blah
$json_array = json_decode($json_file, true);
if (isset($json_array[0]) && $json_array[0]['name'] == "live_user_{$channel}")
{
$channelTitle = $json_array[0]['channel']['title'];
$title = $json_array[0]['channel']['status'];
$game = $json_array[0]['meta_game'];
?>
<!-- live channel code here -->
on
<!-- end live channel code -->
<?php
}
else
{
?>
<!-- offline channel code here -->
off
<!-- end offline channel code -->
<?php
}
?>


#2 Niveaulos

Niveaulos
  • Members
  • Posts: 2

Posted 19 June 2013 - 06:46 PM

You won't need any php code for that. Always remember: PHP is server side and a stream always goes directly to the browser (otherwise you would have to open a stream from twitch to your server and then open a stream from your server to the browser ;) ). Anyways: here's the html you'll need for that:

Note: I'm currently unable to post links, so you have to replace the spaces inside the link.

<object type="application/x-shockwave-flash" height="300" width="400" data="h t t p : / / w w w . twitch . tv/widgets/live_embed_player.swf?channel={CHANNEL_NAME}">
<param name="movie" value="h t t p : / / w w w . twitch . tv/widgets/live_embed_player.swf?channel={CHANNEL_NAME}"></param>
<param name="allowScriptAccess" value="always"></param><param name="allowNetworking" value="all"></param>
<param name="allowFullScreen" value="true"></param>
<param name="flashvars" value="hostname=w w w . twitch . tv&start_volume=25&channel={CHANNEL_NAME}&auto_play=true"></param>
</object>

simply replace {CHANNEL_NAME} with the name of your twitch channel (that's the one here --> twitch.tv/{CHANNEL_NAME}) and you're good to go :)

hope this could help.

Greetings from Switzerland
- Niveaulos

#3 Zwacky

Zwacky
  • GW2 Team
  • Curse Premium
  • Humanclass_name
  • EU-Frostwolf
  • Blutdurst
  • Posts: 44
  • Talents: Holy

Posted 20 June 2013 - 10:30 AM

actually the code you posted is right, if you just wanna check whether stream-xy is online or not.
but keep in mind, this queries the twitch api, means it takes some time to execute, hence makes your site loading slower.
also if you have a lot of visitors, you will run into throttling issue. more than 1 visit per minute for every minute in an hour is enough to exceed the query limit. to prevent this, you usually make these api calls from a cronjob. but something tells me, that this would be out of scope taking into account that you're struggling with opening php files.

if you intend on embedding the stream onto your site, then the snippet from niveaulos is the way to go.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

<