i generated Oath token in this service https://twitchtokengenerator.com, cause this method from guide dont work for me:
GET https://id.twitch.tv/oauth2/authorize
?client_id=<your client ID>
&redirect_uri=<your registered redirect URI>
&response_type=code
&scope=<space-separated list of scopes>
anyway this code don’t work… i think it’s some problem with checking the channel status. sorry for wasting your time
<?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($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 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';
}
}
?>