PHP Authentication Basic Setup

Hi Dreink!

I’m also a bit new to the Twitch API, but I think you need to change your header.

According to Twitch API MIME types, (https://github.com/justintv/Twitch-API) you should use the following as header. (Not sure if this solve your problem tho).

application/vnd.twitchtv.v3+json 

What I would suggest is to use cURL instead to make a HTTP request.

A simple cURL request would look like the following:

$curl = curl_init();
	$arr = array(
		'client_id' => 'Client_id',
		'client_secret' => 'Client_secret',
		'grant_type' => 'authorization_code', //Do not change this
		'redirect_uri' => 'Redirect_uri',
		'code' => $user_code,
                'state' => NULL
		);
	curl_setopt_array($curl, array(
		CURLOPT_SSL_VERIFYPEER => FALSE,
		CURLOPT_FOLLOWLOCATION => FALSE,
		CURLOPT_URL => 'https://api.twitch.tv/kraken/oauth2/token/',
		CURLOPT_POSTFIELDS => $arr,
		CURLOPT_RETURNTRANSFER => TRUE
		));
        $resp = curl_exec($curl);
        curl_close($curl);

(Not sure if above really works, but it should - have not tried it out yet in PHP)