Script Help - I'm New!

Sorry for what’s probably a really stupid question but new to all this, trying to teach myself and been playing with the following script for 4 hours…

import discord
import requests
import json

client = discord.Client()

# Replace YOUR_TWITCH_CLIENT_ID with your actual Twitch client ID
headers = {'Client-ID': 'TWITCH APPLICATION ID'}

# List of usernames (Twitch Usernames to Track)
usernames = ['KYRR4pt0r']

while True:
    for username in usernames:
        # Get the user's ID from their username
        url = f'{username}'
        response = requests.get(url, headers=headers)
        data = json.loads(response.text)
            user_id = data['data'][0]['id']
        except IndexError:
            print(f"{username} not found")

        # Check if the user is currently streaming
        url = f'{user_id}'
        response = requests.get(url, headers=headers)
        data = json.loads(response.text)

        if data['data']:
            print(f'{username} is online!')
            print(f'{username} is offline.')

    # Check the stream status every 60 seconds
    time.sleep(60)"DISCORD BOT ID")

I keep getting the follwing error back which apparently is to do with my Twitch app id or some sort of Auth Issue. Can anyone help me with this - error message below:

r4ptor@D5FA51C:~/Scripts$ {‘error’: ‘Unauthorized’, ‘status’: 401, ‘message’: ‘OAuth token is missing’}
<Response [401]>
Traceback (most recent call last):
File “”, line 22, in
user_id = data[‘data’][0][‘id’]
KeyError: ‘data’

Not sure how to try and resolve this?!

To call the Twitch API requires an oAuth token


You only provided a Cleint-ID header, you didn’t provider or generate an oAuth token to call the API with.

To convert a login to any kind of oAuth token will suffice

But you should review the authentication documentation Authentication | Twitch Developers and decide what token to work with.

Holy moly I’m out of my depth already haha! - Talk about down a rabbit hole… just wanted my discord bot to show when I was online… this might be a little too much!