I’m not sure what you have going on in your script, but hopefully this helps. Both V5 and New API examples.
import requests
chanid = "23161357" # LIRIK's channel ID
userlogin = "joshog"
client_id = "################################"
def request_datav5(id):
headers = {"Client-ID": client_id, "Accept": "application/vnd.twitchtv.v5+json"}
url = "https://api.twitch.tv/kraken/streams/" + chanid
r = requests.get(url, headers=headers).json()
return r
# If a bad channel ID response will be:
# {'error': 'Internal Server Error', 'status': 500, 'message': ''}
# If streamer is offline response will be:
# {'stream': None}
print("\r\nAPI V5 \r\n")
print(request_datav5(chanid))
def request_dataNewAPI(userlogin):
headers = {"Client-ID": client_id, "Accept": "application/vnd.twitchtv.v5+json"}
url = "https://api.twitch.tv/helix/streams?user_login=" + userlogin
r = requests.get(url, headers=headers).json()
return r
# If a bad user login name or offline response will be:
# {'data': [], 'pagination': {}}
print ("\r\nNew API \r\n")
print(request_dataNewAPI(userlogin))
Another thing you can look into is Webhooks:
https://dev.twitch.tv/docs/api/webhooks-reference/#topic-stream-changed