You shouldn’t even use this in production code, it’s unsafe
Helix requires the clientID to be a header. And you didn’t declare an Auth token
No
No this is Kraken data formatting again
You also have no HTTP code checking or error checking
Something more like: (untested off the top of my head, doesn’t include how to fetch an oAuth token
<?php
$names = [
"xxxxxx",
"xxxxxx"
];
$status = [];
foreach ($names as $name) {
$status[$name] = false;
}
$url = "https://api.twitch.tv/helix/streams?user_login=’ . implode(’&user_login=’, $names)";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . $client_id,
'Authorisation: Bearer ' + token
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$info = curl_getinfo($result);
curl_close($ch);
if ($info['http_code'] == 200) {
$result = json_decode($result);
if (json_last_error() == JSON_ERROR_NONE) {
foreach ($result->data as $stream) {
// do stuff with stream
$name = strtolower($stream->user_name);
$status[$name] = true;
}
} else {
echo 'Failed to deocde JSON';
}
} else {
echo 'Failed with ' . $info['http_code'];
}
foreach ($status as $name => $state) {
if ($state) {
echo '<iframe src="https://player.twitch.tv/?channel=' . $name) . '" frameborder="0" allowfullscreen="true" scrolling="no" height="378" width="620"></iframe>';
} else {
echo $name . ' not live';
}
}