Access token issue

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:

These should be numerics, the ID’s of the users in question

So to use the API to send an announcments

as barrycarlyon on the cohhcarnage channel I use 15185913 and 26610234 respectively, not the wordy names

so

  const body = {
    "broadcaster_id": "26610234",
    "moderator_id": "15185913",
    "message": message,
    "color": "primary"
  };

Thanks for answer
Where can i get numerics channel id’s?

Get Users will let you convert any username to a ID

The userID for the token can be gotten from here of the Validate Token endpoint

Wow, i love you.
Very grateful to you <3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.