Hello, this Code below does not work? At an other subdomain does it work, did change the secret and client id for this one, but does not work?
//START
define("CLIENT_ID", "XXXX");
define("CLIENT_SECRET", "XXXX");
$keys1 = false;
if (file_exists(__DIR__ . '/auth.json')) {
$keys1 = json_decode(file_get_contents(__DIR__ . '/auth.json'));
}
$generate_token = true;
if ($keys1) {
// validate the token
$ch991 = curl_init('https://id.twitch.tv/oauth2/validate');
curl_setopt($ch991, CURLOPT_HTTPHEADER, array(
'Authorization: OAuth ' . $keys1->access_token
));
curl_setopt($ch991, CURLOPT_RETURNTRANSFER, true);
$r1 = curl_exec($ch991);
$i1 = curl_getinfo($ch991);
curl_close($ch991);
if ($i1['http_code'] == 200) {
// the token appears good
$generate_token1 = false;
// optional to check the expires
$token1 = json_decode($r1);
if (json_last_error() == JSON_ERROR_NONE) {
if ($token1->expires_in < 3600) {
// less than an hour left
// make a new token
echo 'Token close to expire. Regenerate';
$generate_token1 = true;
}
} else {
echo 'Failed to parse JSON. Assume dead token';
$generate_token1 = true;
}
}
}
if ($generate_token1) {
$ch991 = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch991, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch991, CURLOPT_POST, true);
curl_setopt($ch991, CURLOPT_POSTFIELDS, array(
'client_id' => CLIENT_ID,
'client_secret' => CLIENT_SECRET,
'grant_type' => "client_credentials"
));
$r1 = curl_exec($ch991);
$i1 = curl_getinfo($ch991);
curl_close($ch991);
if ($i1['http_code'] == 200) {
$keys1 = json_decode($r1);
if (json_last_error() == JSON_ERROR_NONE) {
echo 'Got token';
// store the token for next run
file_put_contents(__DIR__ . '/auth.json', $r1, JSON_PRETTY_PRINT);
} else {
echo 'Failed to parse JSON';
}
} else {
echo 'Failed with ' . $i['http_code'] . ' ' . $r;
}
} else {
echo 'Token OK'; echo "</br>"; echo "</br>";
print_r($keys);
}
$channelsApi312b = 'https://api.twitch.tv/helix/users?login=codeSMART78';
$clientId = 'XXXX';
$ch312b = curl_init();
curl_setopt_array($ch312b, array(
CURLOPT_HTTPHEADER => array(
'Client-ID: ' . $clientId,
'Authorization: Bearer ' . $keys1->access_token
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $channelsApi312b
));
$response312b = curl_exec($ch312b);
$resp312b = json_decode($response312b);
$name2b = $resp312b->data[0]->id;
$firstb = "&first=21";
$channelsApi31b = 'https://api.twitch.tv/helix/clips?broadcaster_id=';
$clientId = 'XXXX';
$ch31b = curl_init();
curl_setopt_array($ch31b, array(
CURLOPT_HTTPHEADER => array(
'Client-ID: ' . $clientId,
'Authorization: Bearer ' . $keys1->access_token
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $channelsApi31b . $name2b . $firstb
));
$response31b = curl_exec($ch31b);
$respx = json_decode($response31b);
$videos1 = $respx->data[0]->embed_url;
$tit1 = $respx->data[0]->title;
$gam1 = $respx->data[0]->name;