Show online twitch from members on website

Hi there,

I have a (Dutch) website for gaming (PS4) en want to show Twitch chanels from our members on one of our website pages.

Chanels from members who are not streaming at that moment must be hidden. The Twitch chanal names comes from the database (from member profiles with sql code and will not be the problem). I want to put their Twitch user names in a array.

I have spent many hours to ceate a working code. … no result… have only a mess of code now…

Basic for the code I try is from:

Hope someone here can help me or push me to a right way.

Many Thanks!

Some code:

<code>

</head>
<script src= "http://player.twitch.tv/js/embed/v1.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<?php
$array = array('ninja', 'mbgclan', 'esl_benelux', 'freaknl');
foreach ($array as $nummer => $naam) {   
   echo $naam . "<br>";
?>

<div id="container">
    <div id="streams"></div>
    <div id="log">	
        Events from <?php echo $naam; ?> will appear here.
        <ul id="event-list"></ul>
    </div>
</div>


<script type="text/javascript">
		
	var naam = ['ninja', 'mbgclan', 'esl_benelux', 'freaknl'];
	var nummer = "<?php echo $nummer;?>";	
	var player = "";
	
	var options = {width: '25%', height: '25%', channel: naam[nummer]};
    	var id = 'player-' + naam[nummer];
      
    player = new Twitch.Player('event-list', options);
    player.setMuted(false);
    player.setVolume(1);
    
    player.addEventListener(Twitch.Player.ONLINE, function () {
        	
		$('#event-list').append('<li style="color: darkgreen;">[' + new Date($.now()).toISOString() + '][' + naam[nummer] + '][VISIBLE] ONLINE</li>');
        player = new Twitch.Player('event-list', options);
	
	});
 	
</script>
	
<?php	
}	// next foreach
?>	
</code>

I just used some old PHP I had with some changes and created an example of what I think you are looking for.

What I do is query the teams endpoint for all members then use the list of ID’s (v5 only works with _ids, not usernames) on kraken v5 (so I don’t have to manually update an array every time the team adds/removes a new member) to pull data from the /streams/ endpoint, which will only show members who are currently live. This list is then dumped into a table with clickable links to the streamers. I have included the game and current title on the stream as well.

Check it in action at: http://twitch.apiexampl.es/teams-list.php
and you can see the source at http://twitch.apiexampl.es/teams-list.php.txt

Please ensure you use your own client_id as mine is just being used for an example.
You can peek at some of the other examples at http://twitch.apiexampl.es but be aware some might be dated/defunct at this time.

But I do see in your code you have a player showing, so I’m not entirely sure this is what you are looking for but I think the logic used might help you on your journey.

1 Like

Thank you very much for your reply and the code!
I think this code will help me further.

If possible I prefer to use code by member id’s.
So I will try to edit the code on some places and hope to get it working by Id’s.

Thanks again!

If someone else has an idea or code I will appreciate!

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