# How to get valid Oauth token

**URL:** <https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572>\
**Category:** API\
**Created:** [May 6, 2021, 7:07am UTC](https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572 "2021-05-06T07:07:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![s103071049](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@s103071049](https://discuss.dev.twitch.com/u/s103071049)\
**Post date:** [May 6, 2021, 7:07am UTC](https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572/1 "2021-05-06T07:07:56Z")

</div>

> **[Reference](https://dev.twitch.tv/docs/api/reference/#get-streams)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

Here is my problem. I try to make the same response as the reference above.

```auto
// get streams Example Request #1 in the reference
curl -X GET 'https://api.twitch.tv/helix/streams' \
-H 'Authorization: Bearer 2gbdx6oar67tqtcmt49t3wpcgycthx' \
-H 'Client-Id: wbmytr93xzw8zbg0p1izqyzzc5mbiz'

```

```auto
// my code write in JS
const request = require('request')
const process = require('process')

request(
  oprions = {
    url: `https://api.twitch.tv/helix/streams`,
    headers: {
    	'Client-ID': 'ka1mgyrfu09rtyw1znuocyf6x0xciq',
    	'Accept': 'application/vnd.twitchtv.v5+json',
    	'Authorization': 'Bearer 2gbdx6oar67tqtcmt49t3wpcgycthx'
    }
  },

  (error, response, body) => {
    const json = JSON.parse(body)
    console.log(body)
    console.log(json)
  }

) 

```

but I always get

```auto
{"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}
{ error: 'Unauthorized', status: 401, message: 'Invalid OAuth token' }

```

so how can I get the right authorization? and what’s the mistake I made?  
THANKS LOT

---

<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 6, 2021, 7:55am UTC](https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572/2 "2021-05-06T07:55:49Z")

</div>

The Authentication Docs [https://dev.twitch.tv/docs/authentication](https://dev.twitch.tv/docs/authentication) explain the process of how to get an OAuth token, you can’t just copy the tokens from the examples.

---

<div class="post-metadata">

**Author:** ![s103071049](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@s103071049](https://discuss.dev.twitch.com/u/s103071049)\
**Post date:** [May 6, 2021, 12:37pm UTC](https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572/3 "2021-05-06T12:37:48Z")

</div>

thanks you~ finally, i get the data

---

<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 5, 2021, 12:38pm UTC](https://discuss.dev.twitch.com/t/how-to-get-valid-oauth-token/31572/4 "2021-06-05T12:38:13Z")

</div>

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