Hey.
I am pretty sure I haven’t fully understood or kinda integrated the stuff yet.
I try to automate step 1 of https://dev.twitch.tv/docs/authentication#oidc-authorization-code-flow-id-tokens-and-user-access-tokens
Everything works fine when I put the following link
$authorize_url = ‘https://api.twitch.tv/kraken/oauth2/authorize?client_id=<client_id>&redirect_uri=<redirect_uri>&response_type=code&scope=’ . $client_scope . ‘&state=’ . $stateVal;
on a website and click on it.
Then I receive the access code etc.etc…
However, if I try to execute the following:
echo “Formulating authorization request…”;
$url = ‘https://api.twitch.tv/kraken/oauth2/authorize’;
$data = array(‘client_id’ => $client_id, ‘redirect_uri’ => ‘redirect_uri’, ‘response_type’ => ‘code’, ‘scope’ => $client_scope, ‘state’ => $stateVal);
// use http even if you send requests to https://…
$options = array(
‘http’ => array(
‘header’ => array(
“Content-type: application/x-www-form-urlencoded”,
“Accept: application/vnd.twitchtv.v5+json”,
),
‘method’ => ‘GET’,
‘content’ => http_build_query($data)
)
);
echo “done.\n”;
echo “Opening stream context…”;
$context = stream_context_create($options);
echo “done.\n”;
echo “Receiving answer…”;
$result = file_get_contents($url, false, $context);
echo “done.\n\n”;
from a script, I receive “failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request”.
What am I doing wrong? Is it working at all like this from a script? (yes my file_get_contents is working with https. I, unfortunately, can’t use curl atm.).