$ch = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => 'myclientID',
'client_secret' => 'yoursecrect',
'grant_type' => 'client_credentials'
));
// Retrieve data
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$data whence JSON decode (and the http code in info checked), should return a token to use. Store and reuse the token until it expires.
This should work off the top of my head. Doens’t include code to obtain an already generated token and check it’s validity