Twitch Embed php script help

I’m using a script to display twitch streams on my website and everything works great except for one aspect… Instead of fetching the most popular stream on twitch I want it to fetch the most popular stream within a game category.

(Thanks to matt_thomas for the script BTW)

ORIGINAL:

/* None of the $channels I wanted are avaiable now, so fetch the most popular one */
$backupArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?limit=1’ . $callAPI), true);
if ( $backupArray != null ) {
foreach($backupArray[‘streams’] as $mydata){
if($mydata[’_id’] != null) {
$name = $mydata[‘channel’][‘display_name’];
$viewers = $mydata[‘viewers’];

EDITED:

/* None of the $channels I wanted are avaiable now, so fetch the most popular one */
$backupArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?game=CS:GO’ . $callAPI), true);
if ( $backupArray != null ) {
foreach($backupArray[‘streams’] as $mydata){
if($mydata[’_id’] != null) {
$name = $mydata[‘channel’][‘display_name’];
$viewers = $mydata[‘viewers’];

I have little to no knowledge on what I’m doing so I’m sure it’s a simple fix… Thanks for anyone’s help in advance :slight_smile:

I recognize that code and those variables. :smile:

Also, you want to get:

https://api.twitch.tv/kraken/streams?game=Counter-Strike:%20Global%20Offensive&limit=1

So modify this line

$backupArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?game=Counter-Strike:%20Global%20Offensive&limit=1’), true);

you don’t need the " . $callAPI" bit because that is only if you were restricting it to a list of streamers… if you just want the most popular for a game overall, the change I gave you would work.

You are awesome Matt thank you!

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