Ok I tested the script.
You construct the URL badly, and I typoed the call to curl_getinfo.
it should be
$info = curl_getinfo($ch);
You put
$url = “https://api.twitch.tv/helix/streams?user_login=’ . implode(’&user_login=’, $names)”;
So the URL got screwed up isntead of being constructed correctly.
<?php
$names[] = "xxxxxx";
$names[] = "xxxxxx";
$status = [];
foreach ($names as $name) {
$status[$name] = false;
}
$url = 'https://api.twitch.tv/helix/streams?user_login=' . implode('&user_login=', $names);
$client_id = "xxxxxxxxx";
$token = "xxxxxxxxx";
$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($ch);
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 decode 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';
}
}