# Get token for Chatbots & IRC (API Auth)

**URL:** <https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185>\
**Category:** API\
**Created:** [May 15, 2019, 10:58pm UTC](https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185 "2019-05-15T22:58:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabel](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabel/32/5121_2.png) [@sabel](https://discuss.dev.twitch.com/u/sabel)\
**Post date:** [May 15, 2019, 10:58pm UTC](https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185/1 "2019-05-15T22:58:52Z")

</div>

Hello, I am writing chat-bot for streamer’s chats and I need some help.I use js code from [docs](https://dev.twitch.tv/docs/irc/) and I have problem with token.

In this chapter - [Connecting to Twitch IRC](https://dev.twitch.tv/docs/irc/guide/) 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](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#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](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](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#oauth-authorization-code-flow) via [example](https://github.com/TwitchDev/authentication-samples/tree/master/node) 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?

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [May 15, 2019, 11:02pm UTC](https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185/2 "2019-05-15T23:02:07Z")

</div>

> [@sabel](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [May 16, 2019, 9:29am UTC](https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185/3 "2019-05-16T09:29:05Z")

</div>

> [@sabel](#):
>
> But if I use [OAuth Authorization Code Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#oauth-authorization-code-flow) via [example](https://github.com/TwitchDev/authentication-samples/tree/master/node) I get a valid token and I can work with chat-bot. This way works great - have no questions.

> [@Dist](#):
>
> you’re connecting to chat as a Twitch user, which is the user associated with a User Access Token.

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [June 15, 2019, 9:29am UTC](https://discuss.dev.twitch.com/t/get-token-for-chatbots-irc-api-auth/21185/4 "2019-06-15T09:29:06Z")

</div>

Closed on June 15, 2019, 9:29am UTC

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