Ive made some python code to connect to twitch subscriptions via the websocket api but I keep getting the same response no matter what I try???
{'error': 'Forbidden', 'status': 403, 'message': 'subscription missing proper authorization'}
while trying to subscribe to the channel.follow event type.
I’ve checked the scope of the token used, and i don’t know if I’m missing some scopes but here is the list of the scopes I’m using:
Token scopes: [‘channel:read:subscriptions’, ‘chat:read’, ‘moderator:read:chatters’, ‘user:read:email’]
Here is the full python code i’m using for this:
async def listen_to_websocket():
url = "wss://eventsub.wss.twitch.tv/ws"
async with websockets.connect(url) as websocket:
response = await websocket.recv()
welcome_message = json.loads(response)
session_id = welcome_message['payload']['session']['id']
print(f"Connected with session ID: {session_id}")
headers = {
'Client-ID': config.CLIENT_ID,
'Authorization': f'Bearer {config.ACCESS_TOKEN}',
'Content-Type': 'application/json'
}
follow_subscription = {
'type': 'channel.follow',
'version': '2',
'condition': {
'broadcaster_user_id': config.USER_ID,
'moderator_user_id': config.USER_ID
},
'transport': {
'method': 'websocket',
'session_id': session_id
}
}
subscribe_url = 'https://api.twitch.tv/helix/eventsub/subscriptions'
response = requests.post(subscribe_url, headers=headers, json=follow_subscription)
print("Subscribed to follow event:", response.json())
while True:
message = await websocket.recv()
data = json.loads(message)
if data['metadata']['message_type'] == 'notification' and data['metadata']['subscription_type'] == 'channel.follow':
username = data['payload']['event']['user_name']
print(f"{username} just followed")
I have some issue troubleshooting it, i can’t find informations on the requiered scopes and I think it’s the issue, so if anybody has an idea…
Thank you in advance