Hi, When a viewer used my extension , extension should send a message to chat about that user in that channel. Just want to send a simple message.
I’m working on “send extension chat message” also i tried “Send Extension PubSub Message” too. When i tried pubsub i was getting “403 - JWT could not be verified” error and i cant figure out it. Now i’m trying other way but i’m getting “401 authentication failed” error.
I have read a lot of explanations and posts on this subject and tried a lot of things. I am very confused now.
EBS is writen in PHP.
$payload_arr = array(
“exp” => $time,
“user_id”=> $channelid,
“role”=> “external”
);$payload = json_encode($payload_arr);
// {“exp”:1592921206,“user_id”:“49354541”,“role”:“external”}$jwt = JWT::encode($payload, $secretkey);
// I also check the token at jwt.io too.
//Send Extension Chat Message
$url = “https://api.twitch.tv/extensions/“.$clientid.”/“.$clientversion.”/channels/“.$channelid.”/chat”;
$headers = array(
"Authorization: Bearer ".(string)$jwt,
"Client-Id: ".$clientid,
“Content-Type: application/json”
);$data = array(“text” => ‘Extension send a message to chat’);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_exec($ch);
$dresp = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
Request Header:
[request_header] => POST /extensions/89sl308o9vzckjsz2viv6mx76ihask/1.1.1/channels/49354541/chat HTTP/2
Host: api.twitch.tv
accept: /
authorization: Bearer [token]
client-id: 89sl308o9vzckjsz2viv6mx76ihask
content-type: application/json
content-length: 37
Response;
{“error”:“Unauthorized”,“status”:401,“message”:“authentication failed”}
What am i doing wrong. Thanks for help.