I don’t do a lot in PHP but always preferred GuzzleHttp. The channel ID below belongs to PixelGumTV as I am using v5, I think you are defaulting to v3 based on the code up there and that is about to be made the non-default and third-party support removed early this year.
$client = new GuzzleHttp\Client();
try
{
$response = $client->request('GET',
'https://api.twitch.tv/kraken/streams/115850044',
[ 'headers' => [
'Client-ID' => 'myclientID',
'Accept' => 'application/vnd.twitchtv.v5+json' ]
]);
$result = $response->getBody();
$object = json_decode($result);
var_dump($object);
}
catch (Exception $e)
{
$result = $e->getResponse();
var_dump($result);
}
Right now, offline so just returns NULL:
illusion% php ./test_twitch.php
object(stdClass)#31 (1) {
["stream"]=>
NULL
}
So, swapped to the channels endpoint:
illusion% php ./test_twitch.php
object(stdClass)#31 (23) {
["mature"]=>
bool(false)
["status"]=>
string(82) "S2 Ep.174: Multiplayer Madness! | DAILY STREAM | !schedule !grab !pixelpot !coffee"
["broadcaster_language"]=>
string(2) "en"
["broadcaster_software"]=>
string(12) "unknown_rtmp"
["display_name"]=>
string(10) "PixelGumTV"
["game"]=>
string(24) "The Jackbox Party Pack 4"
.......