Error:
Warning:
file_get_contents(https://api.twitch.tv/kraken/oauth2/token): failed to
open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in /var/www/9inchurl.com/html/youtube/twitchr.php on line 30
My PHP code:
$code = $_GET["code"];
$url = 'https://api.twitch.tv/kraken/oauth2/token';
$data = array('client_id' => 'BLABLABLA', 'client_secret' => 'BLABLABLA',
'grant_type' => 'authorization_code', 'redirect_uri' => 'BLABLABLA', 'code' => $code, 'state' => 'BLABLABLA',);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo "POST RESPONSE: <br>";
var_dump($result);
What am I doing wrong?