Get token for Chatbots & IRC (API Auth)

Hello, I am writing chat-bot for streamer’s chats and I need some help.I use js code from docs and I have problem with token.

In this chapter - Connecting to Twitch IRC are described two ways to get token. I need get token through API.
At first I was trying to get a token by OAuth Client Credentials Flow - it is familiar to me because I am sending many requests in “server-to-server” mode. But in this case when I send request:
POST https://id.twitch.tv/oauth2/token? client_id=<my_client_id>&client_secret=
<my_client_secret>&grant_type=client_credentials&scope=user_subscriptions user_read chat:edit
chat:read channel:moderate whispers:read whispers:edit channel_editor

I get usual response with access_token, I use this access_token for connecting to chat, but I always get error - “Login unsuccessful”

But if I use OAuth Authorization Code Flow via example I get a valid token and I can work with chat-bot. This way works great - have no questions. But it is uncomfortable - I need to open web-page and go to twitch-auth then redirect back to page.

My purpose is to get a token by “server-to-server” way. Is it possible for chat/irc?

No, that’s not possible because you’re not connecting to chat as an App, you’re connecting to chat as a Twitch user, which is the user associated with a User Access Token.

If you want to connect to chat anonymously you can use the login justinfan12345 or any set of numbers at the end, and just an empty password rather than using a token, but you wont be able to send any messages like this.

1 Like

And for a chat bot. you will need to do this ONCE only.

To get the token and refresh tokens.

Then you will only need to do it again, if both your token and refresh token have died, meaning you need new keys.

1 Like

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