400 Bad Request on client_credentials request, but only in production!

Hi Barry, thank you for reaching out

Utterly bizzare honestly, but I did manage to fix it, by simply moving the query string params to postfields

That’s it.

But according to the documentation, the query string params are not only supposed to work, thats the example the docs give.

But I noticed in a previous post of your’s from 2020, that you mentioned that sending the query string and postfields works: https://staging-discuss.dev.twitch.com/t/getting-a-token-400-bad-request/27250/2

So I gave that a shot, and… success :man_shrugging:

$url = "https://id.twitch.tv/oauth2/token";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'client_id' => AppInfo::$Apps['Twitch']->ClientID,
    'client_secret' => AppInfo::$Apps['Twitch']->ClientSecret,
    'grant_type' => 'client_credentials'
]);

$data = curl_exec($ch);
curl_close($ch);

if(!$decodedTwitchData = json_decode($data, true))
{
    throw new Exception("Empty or invlaid return data: {$data}");
}