Can someone help me add client id to this request?

Hello. I don’t know anything about PHP and our script for showing twitch status isn’t working becuase of the client id thats needed now. Can someone help me implement the clientid to this code?

<?php
$idd = explode(",",$_GET['twitch']);
$callAPI = implode(",",$idd);
$dataArray = json_decode(@file_get_contents('https://api.twitch.tv/kraken/streams?channel=' . $callAPI), true);

foreach($dataArray['streams'] as $mydata){
if($mydata['_id'] != null){
	$name 		= $mydata['channel']['display_name'];
	$game		= $mydata['channel']['game'];
	$url		= $mydata['channel']['url'];
	$status		= $mydata['channel']['status'];	

	echo "<p id=\"a1\"><b><a target=\"_blank\" href=\"$url\"><img src=\"https://cdn1.iconfinder.com/data/icons/micon-social-pack/512/twitch-128.png\" width=\"16\" height=\"16\" />&nbsp;" . $name . "</b> jest <b id=\"a2\">ONLINE!</b><br/><b>" .  $game . "</b> - " . $status . "</a></p>";

}
}

You can alter your $dataArray to this:

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

and you just need to define the $clientID token somewhere with the clientID provided on your developer application.

Thank you, it’s working!

On a side note.

Please look at using cURL instead of file_get_contents.

file_get_contents is often disabled on production hosts for security reasons!

1 Like

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