# Api auth error Invalid OAuth token

**URL:** <https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216>\
**Category:** API\
**Created:** [April 10, 2021, 4:29pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216 "2021-04-10T16:29:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [April 10, 2021, 4:29pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/1 "2021-04-10T16:29:47Z")

</div>

Hi  
Could someone help me understand what would be the error of my code below? :

Variables  
self.username = ‘’‘myusername’’’  
self.channel = ‘’‘mychannelname’’’  
self.app\_client\_id = ‘’‘xxxxxx’’’ #from [https://dev.twitch.tv/console/apps](https://dev.twitch.tv/console/apps)  
self.authorization = ‘’‘xxxxx’’’ #from [http://twitchapps.com/tmi/](http://twitchapps.com/tmi/)

Request  
url = ‘[https://api.twitch.tv/helix/search/channels?query=](https://api.twitch.tv/helix/search/channels?query=)’ + self.channel  
headers = {‘client-id’: self.app\_client\_id, ‘Authorization’: 'Bearer ’ + self.authorization}  
r = requests.get(url, headers=headers).json()  
self.channel\_id = r[‘data’][0][‘id’]

Response  
function variables  
‘error’:‘Unauthorized’  
‘status’:401  
‘message’:‘Invalid OAuth token’  
len():3

Thanks!

---

<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:** [April 10, 2021, 4:31pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/2 "2021-04-10T16:31:39Z")

</div>

assuming `self.authorization` is actually populated with the token

Then that would suggest the token is invalid

---

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [April 10, 2021, 4:39pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/3 "2021-04-10T16:39:27Z")

</div>

I took a new token and tried again, same return

---

<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:** [April 10, 2021, 4:43pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/4 "2021-04-10T16:43:13Z")

</div>

is `self.authorization` actually populated when you pass it to that request?

I see you are also using the search endpoint

This python example might be of more use, it’ll generate an App Access Token and do a “is stream live” check instead.

> **[BarryCarlyon/twitch\_misc](https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/app_access_tokens/python)**
>
> main/authentication/app\_access\_tokens/python

And doesn’t rely on someone elses token generator

---

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [April 10, 2021, 5:17pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/5 "2021-04-10T17:17:47Z")

</div>

> [@sabrinabm](#):
>
> ‘message’:‘Invalid OAuth token’

I did a test with your code and got the response below  
{‘status’: 403, ‘message’: ‘invalid client secret’}

so there is a problem with my token, maybe need I use another link besides this one ? [Twitch Chat Password Generator](https://twitchapps.com/tmi/)

---

<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:** [April 10, 2021, 5:20pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/6 "2021-04-10T17:20:05Z")

</div>

> [@sabrinabm](#):
>
> I did a test with your code and got the response below  
> {‘status’: 403, ‘message’: ‘invalid client secret’}

Then you copy/pasted the client secret wrong from the dashboard.

 ![image](https://d2opxh93rbxzdn.cloudfront.net/original/2X/3/3ebffda43003a7276f06f6c28f27cccbe84c829f.png)

---

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [April 10, 2021, 5:38pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/7 "2021-04-10T17:38:58Z")

</div>

ah I got it now, id and secret are from same url: [https://dev.twitch.tv/console/apps](https://dev.twitch.tv/console/apps).

It worked now, thanks !

---

<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:** [May 10, 2021, 5:39pm UTC](https://discuss.dev.twitch.com/t/api-auth-error-invalid-oauth-token/31216/8 "2021-05-10T17:39:03Z")

</div>

Closed on May 10, 2021, 5:39pm UTC

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