OAuth token is missing


Have been looking at this problem now for several hours and I don’t get what is wrong.
Looked at several similar posts and can’t see what I would be missing.

Perhaps it is obvious I am just not seeing it.

I am trying to call the API via Python using requests:

Url = “https://api.twitch.tv/helix/streams
AutURL =“https://id.twitch.tv/oauth2/token
ClientId = “REMOVED”
Secret = “REMOVED”

AutParams = {‘client_id’: ClientId, ‘client_secret’: Secret, ‘grant_type’: ‘client_credentials’}
AutCall = requests.post(url=AutURL, params=AutParams)

AutCall response: {‘access_token’: ‘REMOVED’, ‘expires_in’: 4966678, ‘token_type’: ‘bearer’}

data1 = AutCall.json()
access_token = data1[“access_token”]
Params = {‘Client-ID’: ClientId, ‘Authorization’: ‘Bearer’ + access_token,}

StreamsCall = requests.get(url=Url, params=Params)

StreamsCall response: {‘error’: ‘Unauthorized’, ‘status’: 401, ‘message’: ‘OAuth token is missing’}

As you can see above I successfully get a app access token but have some issue when I try to use it in my get request.

Thankful for any help I can get thank you.

You’re missing a space between ‘Bearer’ and your access token.

If you still have issues, log the request you’re making so you can see the exact headers that are being sent and if they match what you expect them to be.

I have added the space, did not seem to make any difference.

I added some debug log, but still can’t see what could be wrong.
Perhaps some one else can?

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.twitch.tv:443
send: b’GET /helix/streams?Client-ID=REMOVED&Authorization=Bearer+REMOVED HTTP/1.1\r\nHost: api.twitch.tv\r\nUser-Agent: python-requests/2.24.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: /\r\nConnection: keep-alive\r\n\r\n’
DEBUG:urllib3.connectionpool:https://api.twitch.tv:443 “GET /helix/streams?Client-ID=REMOVED &Authorization=Bearer+REMOVED HTTP/1.1” 401 72
reply: ‘HTTP/1.1 401 Unauthorized\r\n’
header: Connection: keep-alive
header: Content-Length: 72
header: access-control-allow-origin: *
header: cache-control: no-cache, no-store, must-revalidate, private
header: content-type: application/json; charset=utf-8
header: expires: 0
header: pragma: no-cache
header: server: envoy
header: timing-allow-origin: https://www.twitch.tv
header: twitch-trace-id: 7e1d8fb7a59074b93fcaffeeac5e69f2
header: x-ctxlog-logid: 1-5f302078-0438df01664f3df946d2e22b
header: Date: Sun, 09 Aug 2020 16:12:40 GMT
header: X-Served-By: cache-sea4456-SEA, cache-bma1620-BMA
header: X-Cache: MISS, MISS
header: X-Cache-Hits: 0, 0
header: X-Timer: S1596989560.263811,VS0,VS0,VE168
header: Vary: Accept-Encoding
header: Strict-Transport-Security: max-age=300

I’m not a Python dev, but it looks like you’re sending the client ID and OAuth token as querystring params which is incorrect. You need to send them as request headers.

Me neither as you can see, but thanks for pointing that out.
It is working now, made these changes:

data1 = AutCall.json()
access_token = data1[“access_token”]
Headers = {‘Client-ID’: ClientId, ‘Authorization’: "Bearer " + access_token}

StreamsCall = requests.get(url=Url, headers=Headers)

Thank you <3

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