OAuth token is missing even though the token was given

Hey i’m having a weird problem while trying to get a userID i keep getting the response from twitch saying

OAuth token is missing

However i do give it a correct Oauth token

def getUserID(Username, OAUTH):

   HEADERS = {'client_id': CLIENT_ID, 'Authorization': 'Bearer ' + OAUTH}
   URL = BASE_URL + "users?login="
   print(URL)

    try:
       req = requests.get(URL, HEADERS)
       print(req)
       jsondata = req.json()
       print(jsondata)

    except Exception as e:
        print("Error getting ID for: ", Username, "Caused by: ", e)

any advice or things i’ve done wrong?

This is python requests yes?

Yes sorry forgot to say

Try

HEADERS = {‘client-id’: CLIENT_ID, ‘Authorization’: 'Bearer ’ + OAUTH}

instead of

HEADERS = {‘client_id’: CLIENT_ID, ‘Authorization’: 'Bearer ’ + OAUTH}

Sadly not still the same response

And OAUTH is actually a token?

heres a similar example

This is the code that gets the OAuth

OAUTHHEADERS = {'client_id': CLIENT_ID, 'client_secret': CLIENT_SECRET, 'grant_type': 'client_credentials'}
OAUTHURL = "https://id.twitch.tv/oauth2/token"

def getOauth():
    try:
       req = requests.post(OAUTHURL, OAUTHHEADERS)
       print(req.json())
       jsondata = req.json()
       if 'access_token' in jsondata:
           print(jsondata['access_token'])
    except Exception as e:
         print(e)

For the getting a token you need to POST as body, this looks like you are sending headers instead, and thus not getting a token out as it’s failing.

(My python is a tad rusty)

It returns what looks to be an oauth token i would send it but idk if thats a security issue or not

never leak your token no.

If the API says it’s missing then your code might not be propgating the generated token to the other function(s)

You was right and i see the problem i forgot to tell my getOAuth function to return the oauth thanks :smiley: It’s useful to have 2 sets of heads at the problem but i am still getting the problem even if it is passing the OAuth token through

I don’t know if this will help but this is what the headers that are added on to the request

{'client-id': 'REDACTED', 'Authorization': 'Bearer REDACTED'}

After more and more searching i can not figure out what i have done wrong everything seems to be coded correctly

A post was split to a new topic: oAuth issue with nodeJS

  • What does you full code look like now?
  • What call is failing
  • What is the error code and body response
  • What request are you making?

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