Removed your key as it counts as a password and shouldn’t be posted publically.
Try this instead, confirmed as working having just tested it, (it’s a bad/old/dumb test script for the chat endpoint I have kicking about in PHP)
For this $user_id should be the ID of the channel that you want to send Chat messages to.
<?php
echo date('r', time());
echo "\n";
$client_id = 'CLIENID';
$secret = base64_decode('SECRET');
$version = '0.0.1';
$user_id = 'CHANNEL_ID';
// end edits
include(__DIR__ . '/jwt.php');
$j = new JWT();
$payload = array(
'exp' => time() + 60,
'user_id' => ''.$user_id,
'role' => 'broadcaster'
);
$bearer = $j->encode($payload, $secret);
echo "\n" . $bearer . "\n";
$data_string = json_encode(array(
'text' => 'This is a test'
));
$url = 'https://api.twitch.tv/extensions/' . $client_id . '/' . $version . '/channels/' . $user_id . '/chat';
echo $url;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $bearer,
'Client-ID: ' . $client_id,
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$r = curl_exec($ch);
$i = curl_getinfo($ch);
curl_close($ch);
echo "\n" . $i['http_code'] . "\n";
echo "\n";
echo $r;
echo "\n";
jwt.php is from https://github.com/firebase/php-jwt/blob/master/src/JWT.php
But my current version of the file is, I only tested against my version as I know it works
Most notably is my payload differs
$payload = array(
'exp' => time() + 60,
'user_id' => ''.$user_id,
'role' => 'broadcaster'
);
However
$payload = array(
'exp' => time() + 60,
'user_id' => '15185913',
'role' => 'external'
);
Also works (my user_id and I own the extension posting to another channel)
+60 for the exp is SUPER LIBERAL really too