I’m trying to make an authentication system for a website using Twitch API. I am developing following the OAuth Authorization Code Flow method. I can get a code but no access token nor refresh token, just a false boolean. I am currently working in localhost. Please find down below my code for the connection with the authentication part. Does any one has any idea of what I am missing?
I was working on PHP 7.3.12. I tried with PHP 7.2.2 but it is still not working. I do have the same false bolean from the API. Can it come from the curl extension of my server?
PHP version shouldn’t be a factor, as it will enforce a specific version of the cURL module anyway.
You could try adding a
$info = curl_getinfo($handle);
print_r($info);
Before the curl_close
It might be that for whatever reason your PHP install can’t communicate with the internet.
Or this could be a SSL error (since we didn’t do a HTTP Code check)
SSL error could be: SSL local Cert bundle missing or out of date.
Your server clock is out too far and can’t verify the connection.
The output of curl_getinfo should provide more information.
It’s also a good idea to do HTTP Code checking whenever you do a request, rather than blindly bassing back the response.
// fetch the data
$r = curl_exec($ch);
// get the information about the result
$i = curl_getinfo($ch);
// close the request
curl_close($ch);
if ($i['http_code'] == 200) {
$token = json_decode($r);
// always a good idea to check the JSON parsed correctly
if (json_last_error() == JSON_ERROR_NONE) {
I check the HTTP Code and I check ifthe JSON actually decoded as expected