0

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

szatmary
  • 29,969
  • 8
  • 44
  • 57
SirCumz
  • 171
  • 1
  • 2
  • 14

1 Answers1

0

Can't you send the token as an URL parameter? Just to test that the token is not invalid.

https://api.twitch.tv/kraken?oauth_token=[access token]

Oliver
  • 3,981
  • 2
  • 21
  • 35
  • yes i tried but getting the same error thats why i tried the header – SirCumz May 09 '14 at 09:55
  • when i go to https://api.twitch.tv/kraken?oauth_token=[access token] it says: ["token"]=> array(2) { ["valid"]=> bool(false) ["authorization"]=> NULL } – SirCumz May 09 '14 at 10:03
  • The token you are using is not valid then (or out of scope). Make sure you follow the procedures defined [here](https://github.com/justintv/Twitch-API/blob/master/authentication.md) to obtain a valid token. – Oliver May 09 '14 at 10:10
  • I read the whole api, access_token becomes invalid when i leave the page where the code is send by twitch – SirCumz May 09 '14 at 10:20