I’m currently working on a (what I thought should be) simple project of using the twitch API in a python program on my desktop. All I want the program to do is to detect if a livestream of a user of a certain username is live. So I got a client ID and am using https://github.com/PetterKraabol/Twitch-Python to write the program in python. However, I am getting 401 Client Error: Unauthorized for url error whenever I try to call anything. I’ve done a bit of research and apparently I need to get an OAuth user access token, and the usual procedure is to redirect the user to authenticate themselves online. I assume this is probably the problem? However, I’m not interested in building a commercial application available to users online, I only want it to function on my desktop. I looked over the OAuth procedures and was confused on how to do it on a python program? Thanks!
edit: I’m sorry if this question is dumb or misguided, I’m completely new to the twitch API and also to programming in general!
I’m not a Python dev so can’t help with debugging the library, but a 401 would likely suggest your Client ID is invalid (eg, you may have copy/pasted some whitespace, or missed characters, etc…). If you log the actual body of the response you’re getting from Twitch it’ll give you the exact reason for the error.
An OAuth token is not currently needed to use the Get Streams endpoint, a Client ID will suffice as long as it is valid. That being said though, from the 30th of April onwards ALL requests to Helix will require both a client ID, and an OAuth token, so you will have no choice but to get an OAuth token, which for requests that don’t require any user scopes you can simply use an App Access Token https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow
Thank you for your response!
Here’s the full error: requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.twitch.tv/helix/streams
My client ID seems to be correct.
Wheres the rest of the message?
You should have a body response that includes something useful to tell you what is actually wrong
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.