Authentication Token for Get User Object

I’ll answer your direct question shortly, but I wanted to bring up a couple of points.

  1. What data do you need form the user object? There is a user by ID API that doesn’t use OAuth that could potentially make this much, much easier.
  2. The code flow you’re using is the Authentication Code flow. You may not need this flow. If this is a client-side application, you can use the Implicit Grant flow.

In general, you can make a request just like you’ve already done. You simply take the access_token value and put it into the Authorization header:

$headers = array(
    'Accept: application/vnd.twitchtv.v5+json',
    'Authorization: OAuth YOURTOKENHERE',
);

$url = 'https://api.twitch.tv/kraken/user';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);

$result = curl_exec($ch);
curl_close($ch);

echo $result;