I am using the Twitch api authorization flow but it keeps saying my access token is not correct when i try to retrieve a user.
The access token Twitch gave me after authorization is stored in the database, then i use cURL to get the user and twitch give me this error:
{"error":"Unauthorized","status":401,"message":"Token invalid or missing required scope"}
The access token is send as a header
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Authorization: OAuth '.$token
));
I searched google for this issue but found nothing relavant, access_token do not expire for as i can tell, can someone please help with this?
$crl = curl_init();
curl_setopt ($crl, CURLOPT_URL,'https://api.twitch.tv/kraken/user');
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt ($crl, CURLOPT_SSL_VERIFYPEER, false);
if($token)
{
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Authorization: OAuth '.$token
));
}
$ret = curl_exec($crl);
curl_close($crl);
I just found out that i can get the user object bu only if i am on the page where twitch redirects me with the "code=[code]", if try to stay on that page and make the cURL request it all works fine, but after i saved the access_token in the database and leave that page the access_token becomes invalid