Is there an easy code snippet to embed the viewer counter into a webpage like there are when you share your video stream and chat? Just a simple html code to display your viewer count?
This will work for you, but doesn’t do any error checking (ie. Is the stream offline? display 0 viewers)
(Disclaimer: I don’t claim to know or be good at writing PHP, I didn’t know how to do this without a foreach even though I didn’t want to use it, but hey… it works)
<?php $channel = "kittyplaysgames"; $dataArray = json_decode(@file_get_contents('https://api.twitch.tv/kraken/streams?channel='.$channel), true); foreach ($dataArray['streams'] as $mydata) { $viewers = $mydata['viewers']; }; echo "$channel has $viewers viewers"; ?>
Thank you kind sir!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.