Error when sending POST to API [PHP]

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?

Missed this header:
Accept: application/vnd.twitchtv.v2+json

I am getting the same error. It worked about 1 week or 10 days ago, but now it is getting this error. Were you able to figure out the problem?

@Wizzup I am getting the same error. Can you explain a little more of where to place or add that line?

Depends on your code, but if you read my code you will see where I put it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.