I got stucked when i try send announce with twitch helix api, always got this error:
Error sending Twitch announcement: {
error: 'Unauthorized',
status: 401,
message: 'incorrect user authorization'
}
I took the token from the link: https://id.twitch.tv/oauth2/authorize?client_id=myAppClientId&redirect_uri=https://localhost:3000&response_type=token&scope=moderator:manage:announcements
async function sendTwitchAnnouncement(message: string) {
const url = `https://api.twitch.tv/helix/chat/announcements`;
const accessToken = "tokenFromLink";
const headers = {
'Authorization': `Bearer ${accessToken}`,
'Client-Id': 'myAppClientId',
};
const body = {
"broadcaster_id": "channelNickname",
"moderator_id": "botNickname",
"message": message,
"color": "primary"
};
try {
await axios.post(url, body, { headers });
console.log("Twitch announcement sent successfully");
} catch (error) {
console.error("Error sending Twitch announcement:", error.response.data);
}
}
thanks a lot for any help c: