Sorry I know you have plenty of these same topics and I read through them all and can’t seem to figure out what I missing.
Below is my code, but no matter what I do I can’t get past the "Invalid authorization code. The other posts mentioned the token being used already and invalid. I am getting the #access_token and immediately sending it to the backend to then get the access_token. As far as I can tell I am not doing it more than once.
Any ideas what I am missing?
$ch = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => $clientId,
'client_secret' => $clientSecret,
'code' => $_POST['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => $_POST['redirectUrl']
));
$r = curl_exec($ch);
// $i = curl_getinfo($ch);
curl_close($ch);
$response = json_decode($r, true);
if ($response['status'] == 200) {
$token = json_decode($r);
if (json_last_error() == JSON_ERROR_NONE) {
echo json_encode($token);
exit;
} else {
$error = 'Failed to parse the JSON at code for token exchange';
}
} else {
$error = 'An Error Occured at code for token exchange: ' . print_r($r, true);
print_r($error);
}