Hello,
i’m new at devloping twitch extentions, have looked at the examples but now i’m stuck.
I have a front end video component that can call my php backend, but i cant send from my backend via pubsub to all user front ends. I guess i do something wrong with the pubsub message.
Hello, I’m trying this in node and somehow am stuck as well. Any suggestions? I always get {“error”:“Unauthorized”,“status”:401,“message”:“authentication failed”} returned to me.
const currentSecret = '<base64 encoded secret copied from extension settings>';
const ChannelId = '<my channel id>';
const OwnerId = '<my user id>';
const ClientId = '<client id from overview on my extension>';
const jwt = require('jsonwebtoken');
const request = require("request");
const secret = Buffer.from(currentSecret, 'base64');
const signedJwt = makeServerToken(ChannelId);
var options = {
url : 'https://api.twitch.tv/extensions/message/' + ChannelId,
headers :{
'Authorization' : 'Bearer ' + signedJwt,
'Client-Id': '<my client id from extensions overview>',
'Content-Type': 'application/json'
},
body : JSON.stringify({
message: { "foo":"bar" },
content_type: 'application/json',
targets: ['broadcast']
})
};
function details(error,response,body) {
console.log(body);
}
request(options, details);
// Create and return a JWT for use by this service.
function makeServerToken(channelId) {
const payload = {
exp: Math.floor(Date.now() / 1000) + 60,
channel_id: String(channelId),
role: 'external',
pubsub_perms: {
send: ['broadcast'],
},
};
return jwt.sign(payload, secret, { algorithm: 'HS256' });
}
Thanks BarryCarlyon! Sorry about posting on this thread instead of making a new one. I found it thru google initially and thought someone else may find that way and then would see something relevant. Won’t do again in the future.