Error when sending POST to API [PHP]


file_get_contents( failed to 
open stream: HTTP request failed! HTTP/1.1 400 Bad Request
 in /var/www/ on line 30

My PHP code:

$code = $_GET["code"];

$url = '';

$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>";

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.