Invalid Client Secret when trying to get Access Token

Your curlopt_postfields is incorrectly formatted

See twitch_misc/authentication/app_access_tokens/php at main · BarryCarlyon/twitch_misc · GitHub for a PHP example

Should be an array like

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'client_id' => CLIENT_ID,
    'client_secret' => CLIENT_SECRET,
    'grant_type' => "client_credentials"
));