0

I have been unable to get an OAuth token. I have spent about 4 hours trying. The various iterations and changes the Twitch API has been through is leaving me unsure and confused. The Twitch Developers now have a message posted stating V5 API being decommission on February 28th 2022. I am lost.

This is where I am at right now. The "code" below is from the Getting authorization code here.

<?php

    function file_get_contents_curl($url) {
        $curlHeader = [
            'client_id' => '"CLIENT ID"',
            'client_secret' => '"CLIENT SECRET"',
            'code' => '"POST TOKEN"',
            'grant_type' => '"AUTHENTICATION CODE"',
            'redirect_uri' => 'https://rons-home.net'
        ];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
        $data = curl_exec($ch);

        curl_close($ch);
        return $data;
    }

print_r( file_get_contents_curl( 'https://id.twitch.tv/oauth2/authorize' ) );

Response

{"status":400,"message":"missing response type"}
Ron Piggott
  • 705
  • 1
  • 8
  • 26
  • 1
    You are currently trying to send what _should_ actually be POST parameters, as HTTP headers instead. – CBroe Feb 28 '22 at 07:57

1 Answers1

0

This is a valid curl call to do the Step 3 of user oAuth

Most notably:

  • you were trying to pass paramters as a header
  • And you have extra " littered in your paramerters
  • And your grant type if very wrong

Substitute the constants as needed.

        $ch = curl_init('https://id.twitch.tv/oauth2/token');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            'client_id' => CLIENT_ID,
            'client_secret' => CLIENT_SECRET,
            'code' => $_GET['code'],
            'grant_type' => 'authorization_code',
            'redirect_uri' => REDIRECT_URI
        ));

        // fetch the data
        $r = curl_exec($ch);
        // get the information about the result
        $i = curl_getinfo($ch);
        // close the request
        curl_close($ch);
Barry Carlyon
  • 1,039
  • 9
  • 13