First off, itâs not recommended to use 3rd party token generators, they are not run by Twitch and so there are risks involved. You should ideally generate tokens yourself.
As for the issue, it could be a number of things. You donât show what fetchAccessToken() does, so we have no way to know about that. It could be the token you have doesnât have the channel:manage:polls scope, it could be that the token is not for the correct user (eg, if you created a token with your own account, you can only create a poll on your own account, if you want to create a poll on another channel then that other channel will need to go through the OAuth flow and grant you a token).
Also it would be helpful if you log the body of the response, as that will contain more information about the error rather than just logging the status code.
my bad sorry⌠I have not been able to be smart enough to manage the scope of the oauth token like manging polls and chats thats why i used the third party token⌠but good point âŚ
this is my fetchAccessToken function:
// Function to fetch a new access token
async function fetchAccessToken() {
try {
const response = await fetch(https://id.twitch.tv/oauth2/token, {
method: âPOSTâ,
headers: {
âContent-Typeâ: âapplication/x-www-form-urlencodedâ
},
body: new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
grant_type: âclient_credentialsâ
})
});
if (!response.ok) {
throw new Error(`Failed to fetch access token: ${response.statusText}`);
} //else {
//log response
//console.log(response);}
const data = await response.json();
accessToken = data.access_token;
console.log('Access Token:', accessToken);
} catch (error) {
console.error('Error fetching access token:', error);
process.exit(1);
}
}
I created a separate twitch account which would act as the bot an created the app here in the twitch dev console. I then used the bot account identity to log on to my channel using this:
const opts = {
identity: {
username: âSlurbScatBotâ, // Your botâs username
password: âoauth:uz2XXXXXXXXXXXXXXXXXXXâ // OAuth token for authentication this is from tmi
},
channels: [
âslurbisaurâ // The channel the bot will join
]
};
For API cred s I used the info on the twitch dev console i got after creating the app
Client Credentials creates an App token, not a User token. As such as it has no user permissions as it doesnât represent a user, and so for the most part it canât use any endpoints that requires scopes from a user.
If this is just for your own use, Iâd recommend just using the Twitch CLI. It can help you generate User Tokens, will temporarily host a server to handle the OAuth process, and youâll have an Access Token and a Refresh Token so that you can programmatically get new tokens as the old ones expire and not have to go through the OAuth process again.
The user comes to your webpage (yes that could be you)
Then get sent to twitch to authorized the ClientID access
They come back to your webpage with a ?code= (if the user accepts the link request)
You exchange the code for a token (and refresh token)
So the redirect URI is the URL to the script that handles the code to token exchange. So only you know what it is once you have built it and put it somewhere.
That could be a page on http://localhost if itâs just for personal use or a publically accessable website for ease of key generation (without having to start the local server first).
The TwitchCLI as dist mentioned does this all for you inside itself with a redirect URI set by the people that wrote the TwitchCLI (http://localhost:3000 iirc check ths documentation for sure and setup instructions)
You need the bot account and auth from it to read/send messages to chat as the bot.
You need auth from the channel that you want to run polls on.
So you need the bot account if you want to send messages in chat as the bot
ok so I setup Twitch CLI and gave it my app creds it generated an user access token for me with: " twitch token -u -s chat:edit chat:read channel:manage:polls channel:read:polls"
this token i then used in my script instead of the access token and removed my fetchAccessToken() function.
I sadly am still getting no response from twitch
but the bot seems to be able to join the chat: ââ * Connected to irc-ws.chat.twitch.tv:443""
ahh ok I see, so it is not possible to have the bot manage the poll and the chat results as well as posting the pol to the chat? because currently I have the application created on my bot account with clientID and secret⌠the main account is only referenced in my code as the channel the bot would join⌠do I use the oauth: âusertokenâ and then below in api creds for the access token the same one?
You can but the script uses the broadcasters token.
So it creates/manages the poll using another key
So you use token for the bot to connect to chat
And you use the token for the broadcaster to make the API calls to create/manage a poll
Mod note: removed your image as it leaked your client secret. (with should be kept secret)
ClientIDâs are considered public, which you did censorâŚ
Tokens are natuarlly secret, which you did censor)
As per the image, that I removed, a username is alllowercase not WithCapitalLetts
And a channel name is JUST the username slurbisaur not the URL to the channel, offhand I forget if tmi.js requires this to be prefixed with a # or not, but I donât use tmi.js
for clarification, for me in order to generate an access token for the bot in the twitch cli i would use the app created on the botâs account dev console ? in order to even get a separate token for my broadcaster account i would need a different app on that account and client ID to get a new token form Twitch cli or can I just generate another one ?