# Invalid OAuth token error trying to get Streams API

**URL:** <https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424>\
**Category:** API\
**Created:** [September 7, 2021, 10:33pm UTC](https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424 "2021-09-07T22:33:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![3V1LXD](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3v1lxd/32/13354_2.png) [@3V1LXD](https://discuss.dev.twitch.com/u/3V1LXD)\
**Post date:** [September 7, 2021, 10:33pm UTC](https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424/1 "2021-09-07T22:33:49Z")

</div>

I’m getting an unauthorized error trying to get the data from the streams api:

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

I’ve tried passing both my App Access Token and the Users OAuth token with no success. I’m using the following python code to call the api:

```auto
twitch_api_url = 'https://api.twitch.tv/helix/'

def twitch(endpoint, token, **kwargs):

    headers = {

        'Authorization': 'Bearer %s' % token,

        'Client-Id': settings.TWITCH_CLIENT_ID

    }

    url = twitch_api_url + endpoint

    response = requests.get(url, headers=headers, params=kwargs)

    return response.text

```

Whenever i logout it should be getting rid of the old tokens stored in localstorage so the tokens that i’m using should be new and not expired. I’m not sure what i am missing?

---

<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:** [September 7, 2021, 11:19pm UTC](https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424/2 "2021-09-07T23:19:05Z")

</div>

Then your token expired, or you are not passing what you _think_ you are passing to the headers. (Possibley that the `token` is blank/missing when calling the function)

You can use [Authentication | Twitch Developers](https://dev.twitch.tv/docs/authentication#validating-requests) to validate a token.

> [@3V1LXD](#):
>
> should

Should being the operative word but might not be the case.

Also _really_ shouldn’t be storing an “app access token” in localstorage since that doesn’t belong to the user using your site.

---

<div class="post-metadata">

**Author:** ![3V1LXD](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3v1lxd/32/13354_2.png) [@3V1LXD](https://discuss.dev.twitch.com/u/3V1LXD)\
**Post date:** [September 8, 2021, 2:43am UTC](https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424/3 "2021-09-08T02:43:12Z")

</div>

> [@BarryCarlyon](#):
>
> you are not passing what you _think_ you are passing

You were right thanks for the hint.

> [@BarryCarlyon](#):
>
> Also _really_ shouldn’t be storing an “app access token” in localstorage since that doesn’t belong to the user using your site.

Ok

---

<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:** [October 8, 2021, 2:43am UTC](https://discuss.dev.twitch.com/t/invalid-oauth-token-error-trying-to-get-streams-api/33424/4 "2021-10-08T02:43:57Z")

</div>

Closed on October 8, 2021, 2:43am UTC

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