# How to take token for chat's conversation?

**URL:** <https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357>\
**Category:** Chat and IRC\
**Created:** [February 19, 2018, 11:00am UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357 "2018-02-19T11:00:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 19, 2018, 11:00am UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/1 "2018-02-19T11:00:56Z")

</div>

I tried to take chatroom’s conversation content.(I arranged my question.)

I got token by used this URL  
POST [https://api.twitch.tv/kraken/oauth2/token?client\_id={client\_id}&client\_secret={client\_secret}&grant\_type=client\_credentials&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/token?client_id=%7Bclient_id%7D&client_secret=%7Bclient_secret%7D&grant_type=client_credentials&scope=chat_login)

Result is below.  
{  
“access\_token”: “ **{tokenValue}** ”,  
“refresh\_token”: “”,  
“scope”: [  
“chat\_login”  
],  
“expires\_in”: 5272120  
}

So, I used the **tokenValue** in below source .  
[This source’s position is in Get started\>Code Samples\>Chat\>javascript]  
index.html…  
window.chatClient = new chatClient({  
channel: ‘#{channelid}’,  
username: ‘{my\_userid}’,  
password: ‘oauth: **{tokenValue}** ’  
});  
…

So, I couldn’t get chat’s conversation.  
But, I could get token in url below.  
– [https://twitchapps.com/tmi/](https://twitchapps.com/tmi/)

I don’t know my mistake. What is different something?

I must take token in source(javascript).

How to take token for chat’s conversation?

---

<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:** [February 19, 2018, 11:25am UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/2 "2018-02-19T11:25:13Z")

</div>

This example [https://github.com/twitchdev/chat-samples/blob/master/javascript/index.html](https://github.com/twitchdev/chat-samples/blob/master/javascript/index.html) ?

All that example does is generate a leaderboard based on messages in a given time frame

You’d have to modify the code near [https://github.com/twitchdev/chat-samples/blob/master/javascript/chatbot.js#L92](https://github.com/twitchdev/chat-samples/blob/master/javascript/chatbot.js#L92) to do other stuff with a incoming message.

Your token logic is correct, [Twitch Chat Password Generator](https://twitchapps.com/tmi/) will return a valid token also.

So, what do you actually mean by:

> [@pororia](#):
>
> So, I couldn’t get chat’s conversation.

---

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 19, 2018, 4:08pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/3 "2018-02-19T16:08:27Z")

</div>

Thank for your quick answer.

Sure, I modified this code to take message in chatroom.

So, I tested 2 way.

I used token received via URL.  
POST [https://api.twitch.tv/kraken/oauth2/token?client\_id={client\_id}&client\_secret={client\_secret}&grant\_type=client\_credentials&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/token?client_id=%7Bclient_id%7D&client_secret=%7Bclient_secret%7D&grant_type=client_credentials&scope=chat_login)

It occured “Login authentication failed.”  
like below .

 ![get_post_token](https://d2opxh93rbxzdn.cloudfront.net/original/2X/a/adb8d93a28e839d230ce6d23ea6baa0d7e6b221c.jpg)

But, When I used token received via Twitch Chat OAuth Password Generator. It worked normal.  
like below

[Twitch Chat OAuth Password Generator : [Twitch Chat Password Generator](https://twitchapps.com/tmi/)]

 ![Twitch Chat OAuth Password Generator](https://d2opxh93rbxzdn.cloudfront.net/original/2X/c/c97dc1064793c01efd31ba72df56ef5ca4dda82b.jpg)

I want to know about my mistake.  
Do failed for taking token? or other something?

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [February 19, 2018, 4:14pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/4 "2018-02-19T16:14:26Z")

</div>

> [@pororia](#):
>
> POST [https://api.twitch.tv/kraken/oauth2/token?client\_id={client\_id}&client\_secret={client\_secret}&grant\_type=\*\*client\_credentials\*\*&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/token?client_id=%7Bclient_id%7D&client_secret=%7Bclient_secret%7D&grant_type= **client_credentials** &scope=chat_login)

You need to use one of the grant flows that provides a **user access token**. An **app access token** via the client credentials flow will not work.

See [Authentication | Twitch Developers](https://dev.twitch.tv/docs/authentication) under “Getting Tokens”

App access tokens are using to authenticate your application so they cannot take any action on behalf of another user such as logging into chat. They are currently only useful for Drops and higher rate limits in Helix right now.

---

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 19, 2018, 4:16pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/5 "2018-02-19T16:16:14Z")

</div>

After getting token at URL below, Need next something step?

POST [https://api.twitch.tv/kraken/oauth2/token?client\_id={client\_id}&client\_secret={client\_secret}&grant\_type=client\_credentials&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/token?client_id=%7Bclient_id%7D&client_secret=%7Bclient_secret%7D&grant_type=client_credentials&scope=chat_login)

Can immediately use token? after add"oauth:"  
ex\> oauth:{token}

---

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 19, 2018, 4:43pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/6 "2018-02-19T16:43:49Z")

</div>

Thank you for your answer.

I called URL to take token. like below  
[https://api.twitch.tv/kraken/oauth2/authorize?client\_id={client\_id}&redirect\_uri={webapplicationuri}&response\_type=code&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/authorize?client_id=%7Bclient_id%7D&redirect_uri=%7Bwebapplicationuri%7D&response_type=code&scope=chat_login)  
This URL is User Access Token.  
But I had same result.  
(message.data = :tmi.twitch.tv NOTICE \* :Login authentication failed)

Do I have something problem?

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [February 19, 2018, 4:46pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/7 "2018-02-19T16:46:56Z")

</div>

Take the resulting access token and run it through:

```auto
https://api.twitch.tv/kraken?oauth_token=YOUR_ACCESS_TOKEN

```

Make sure `chat_login` is listed in scopes and the username of the person logging in is in the user\_name field. This make check if the token is even valid.

---

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 19, 2018, 5:12pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/8 "2018-02-19T17:12:50Z")

</div>

Sorry, I don’t understand.  
I am starter about it. So, I ask you to understand.

What is URL’s YOUR\_ACCESS\_TOKEN ? 1) or 2) ?  
[https://api.twitch.tv/kraken?oauth\_token=YOUR\_ACCESS\_TOKEN](https://api.twitch.tv/kraken?oauth_token=YOUR_ACCESS_TOKEN)

1. [https://api.twitch.tv/kraken/oauth2/authorize?client\_id={client\_id}&redirect\_uri={webapplicationuri}&response\_type=code&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/authorize?client_id=%7Bclient_id%7D&redirect_uri=%7Bwebapplicationuri%7D&response_type=code&scope=chat_login)

2)[https://api.twitch.tv/kraken/oauth2/token?client\_id={clinet\_id}&client\_secret={client\_secret}&grant\_type=client\_credentials&scope=chat\_login](https://api.twitch.tv/kraken/oauth2/token?client_id=%7Bclinet_id%7D&client_secret=%7Bclient_secret%7D&grant_type=client_credentials&scope=chat_login)

After I tested as 1). I called URL that you suggested me.  
And I got result like below.  
{“error”:“Bad Request”,“status”:400,“message”:“No client id specified”}

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [February 19, 2018, 5:20pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/9 "2018-02-19T17:20:27Z")

</div>

I do not think you are fully understanding the OAuth handshake process.

Since you appear to be creating a client side application you want to to use the [OAuth Implicit Code Flow](https://dev.twitch.tv/docs/authentication#oauth-implicit-code-flow-user-access-tokens).

The general process is as follows:

1. User opens your application and clicks Login and is directed to: `https://api.twitch.tv/kraken/oauth2/authorize?client_id=<your client ID>&redirect_uri=http://localhost:3000/public/chatbot.html&response_type=token&scope=chat_login`
2. User accepts the OAuth request via their browser and is redirected back to your application at the redirect\_uri
3. The app access token will be in the URL hash: `http://localhost:3000/public/chatbot.html#access_token=XXXXXXX&scope=chat_login`
4. You pull the access\_token from the hash and then pass it to your IRC connection logic.

---

<div class="post-metadata">

**Author:** ![pororia](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pororia/32/7656_2.png) [@pororia](https://discuss.dev.twitch.com/u/pororia)\
**Post date:** [February 20, 2018, 3:43pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/10 "2018-02-20T15:43:01Z")

</div>

Thank you very much!!

I succeeded test that take chat’s message.

I could resolved because your advice.

---

<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:** [March 22, 2018, 3:43pm UTC](https://discuss.dev.twitch.com/t/how-to-take-token-for-chats-conversation/14357/11 "2018-03-22T15:43:07Z")

</div>

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