API php help please (SOLVED)

I used to use this awhile back but with the new update Im not sure exactly what to add in for the clientid and were.
Can someone please help me get this php snip working?

<?php

$channels = array(“username1”, “username2”, “username3”, “username4”) ;
$callAPI = implode(“,”,$channels);
$arrContextOptions=array(
“ssl”=>array(
“verify_peer”=>false,
“verify_peer_name”=>false,
),
);
$dataArray = json_decode(file_get_contents(‘https://api.twitch.tv/kraken/streams?channel=’ . $callAPI, false, stream_context_create($arrContextOptions)), true);

foreach($dataArray[‘streams’] as $mydata){

if($mydata[‘_id’] != null){
$name = $mydata[‘channel’][‘display_name’];
$game = $mydata[‘channel’][‘game’];
$url = $mydata[‘channel’][‘url’];

  echo "ONLINE";

}
}
if($dataArray[‘streams’] == null or $dataArray[‘streams’] == “”)
{
echo “OFFLINE”;
}
?>

You can get your Client ID from your App on Twitch (see this blog)

But see below for the updated line, you need to make sure to declare the $clientID as well:

$clientID = 'CLIENTIDHERE'
$dataArray = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams?channel=' . $callAPI . '&client_id=' . $clientID, false, stream_context_create($arrContextOptions)), true);

Thanks Larklen
So this is what I have but it breaks my whole page. Im not sure what to do to fix.

<?php $channels = array("fatpally", "dyannatv", "mongervog") ; $callAPI = implode(",",$channels); $clientID = 'MYTWITCHCLIENTID' $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $dataArray = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams?channel=' . $callAPI . '&client_id=' . $clientID, false, stream_context_create($arrContextOptions)), true);

foreach($dataArray[‘streams’] as $mydata){

if($mydata[‘_id’] != null){
$name = $mydata[‘channel’][‘display_name’];
$game = $mydata[‘channel’][‘game’];
$url = $mydata[‘channel’][‘url’];

echo “ONLINE”;
}
}
if($dataArray[‘streams’] == null or $dataArray[‘streams’] == “”)
{
echo “OFFLINE”;
}
?>

I used a php code checker online and got this response

PHP Syntax Check: Parse error: syntax error, unexpected ‘$arrContextOptions’ (T_VARIABLE) in your code on line 5
$arrContextOptions=array(

Any help fixing to get the php script working again.

The problem is the below line - I typed my example quickly and left out the semicolon, so that’s breaking your script.

$clientID = 'MYTWITCHCLIENTID' should be $clientID = 'MYTWITCHCLIENTID';

But ensure that you go and pull your ClientID and put it in that variable, otherwise the script still will not work.

Thanks so much.
:smiley:

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