Twitch API PHP Curl /user error 401

So I’ve got my auth token back successfully but when I try run the /user part it just says invalid auth code or scope.

The scope on my auth code that comes back is user_read and on the twitch api page it says this is all it needs to use /user.

The code:

$token = $jresult[‘access_token’];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ‘’);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'Authorization: OAuth '.$token );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$retval = curl_exec($ch);

curl_close ($ch);

$result = json_decode($retval, true);

What am I doing wrong to cause this? Been trying to figure it out for 3hours now.

I tried this through php, and got this result. When I tried it with the same token through shell, it worked just fine. Maybe it’s a problem with the PHP code somehow?

Thanks for the reply. It turned out to be the previous curl call than this that wasn’t pulling the auth keys properly. Couldn’t get it right myself so use the twitch interface to pull that then the code above to get the user stuff. Just incase anyone else comes across the same kind of problem.