First, the use case indicated, you will need to generate an app access token
That is documented here https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow
And I have a python example here https://github.com/BarryCarlyon/twitch_misc/tree/master/authentication/app_access_tokens/python
Then store that token.
You should use this token till it expires
That token is then used with the streams endpoint
So something like this should do the trick (not tested I don’t do python). this just fixes the call, and doesn’t glue to two parts together
import requests
API_HEADERS = {
'Client-ID' : 'myClientID',
'Authorization' : 'Bearer '+token,
}
def checkUser(userName): #returns true if online, false if not
url = 'https://api.twitch.tv/helix/streams?user_login='+userName
try:
req = reqSession.get(url, headers=API_HEADERS)
jsondata = req.json()
if len(jsondata['data']) == 1
return True
else:
return False
except Exception as e:
print("Error checking user: ", e)
return False
print(checkUser("bikestreaming"))
Edit: python code fix