Hey Guys, I want a program to test if a streamer is live and if so switching an OBS scene. I’m not really into programming and especially not the twitch API. I found this code to check if a streamer is live but it’s not working for me. It’s just returning “None”.
import requests
TWITCH_STREAM_API_ENDPOINT_V5 = "https://api.twitch.tv/kraken/streams/bikestreaming"
API_HEADERS = {
'Client-ID' : 'myClientID',
'Accept' : 'application/vnd.twitchtv.v5+json',
}
reqSession = requests.Session()
def checkUser(userID): #returns true if online, false if not
url = TWITCH_STREAM_API_ENDPOINT_V5.format(userID)
try:
req = reqSession.get(url, headers=API_HEADERS)
jsondata = req.json()
if 'stream' in jsondata:
if jsondata['stream'] is not None: #stream is online
#print('online')
return True
else:
return False
#print('offline')
except Exception as e:
print("Error checking user: ", e)
return False
print(checkUser("bikestreaming"))
Ok now I’m getting back “False” (not from the Exception).
I’m not quite sure if I understood you right. Is it right to put the client secret as the token?
Line 17 of my example, will print out the “keys”, one of the items in the object will be expires_in that tells you how long the key is good for. Generally speaking App Access Tokens last around 60 days.