0

Example:

twitch.tv/sadasjdlkasdkjlad returns "invalid user"

twitch.tv/twitch returns "valid user"

So far, I have tried requests to check if twitch returns a 404 for invalid user, but it always returns 200 regardless. Other answers I found use kraken, which appears to no longer work.

code:


client_id = '(insert id)'
client_secret = '(secret)'
streamer_name = 'sasdaasdsdasad'

body = {
    'client_id': client_id,
    'client_secret': client_secret,
    "grant_type": 'client_credentials'
}
r = requests.post('https://id.twitch.tv/oauth2/token', body)

#data output
keys = r.json();

print(keys)

headers = {
    'Client-ID': client_id,
    'Authorization': 'Bearer ' + keys['access_token']
}
r= requests.get("https://api.twitch.tv/helix/streams?user_login=kitboga",headers=headers)
q=json.loads(r.text)

print(q)

#r= requests.get("https://api.twitch.tv/helix/videos/",headers=headers)
#print(r.url)
#print(r.status_code)

This post has a version with helix, but it can treats invalid users like offline ones. Is There Any Way To Check if a Twitch Stream Is Live Using Python?

yungcoder
  • 113
  • 1
  • 1
  • 6

0 Answers0