twitch Getting an OAuth token using the Authorization Code Flow Exchange the code for the OAuth token


Now that you have an authorization code, you can make a POST to the token endpoint ( to get an OAuth token. You will receive a JSON-encoded access token, refresh token, and a list of the scopes approved by the user. You can now use that token to make authenticated requests on behalf of the user.

  $authCode = $_GET['code'];

  $parameterValues = array(
    'client_id' => '...',
    'client_secret' => '...',
    'grant_type' => 'authorization_code',
    'redirect_uri' => 'http://localhost/',
    'code' => $authCode

  $postValues = http_build_query($parameterValues, '', '&');

  $ch = curl_init();
  curl_setopt_array($ch, array(
    CURLOPT_URL => '',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $postValues
  $response = curl_exec($ch);

  echo $response;