Sorry here you can find my code in plain text:
<?php
namespace App;
class TwitchApi
{
private $client;
private $secret;
private $redirect;
public function __construct(string $client, string $secret, string $redirect)
{
$this->client = $client;
$this->secret = $secret;
$this->redirect = $redirect;
}
public function get_tokens(string $code)
{
$link = "https://id.twitch.tv/oauth2/token";
$handle = curl_init($link);
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array(
'client_id' => $this->client,
'client_secret' => $this->secret,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirect,
'code' => $code
));
$response = curl_exec($handle);
curl_close($handle);
return $response;
}
}
I did check with the link you sent and the only thing that is changing is the use of curl_getinfo() (apart from the http_build_query).