WebSocket EventSub Token problem

Hey, im trying to create a WebSocket where i would get the events that im trying to suscribe with EventSub, but when i try to subscribe, it throws me this error : {"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}

        const headers = {
          'Client-ID': clientId,
          'Authorization': `Bearer ${accessToken}`,
        };
        const data = {
          "type": "stream.online",
          "version": "1",
          "condition": {
            "broadcaster_user_id": "134112649"
          },
          "transport": {  
            "method": "websocket",
            "session_id": `${id}`
          }
        };

          const response = await axios.post(`https://api.twitch.tv/helix/eventsub/subscriptions`, data,{headers});

Right now im sending the Client Secret (of the app) and it throws the error i said before, but if i try to send the token that returns the next code it just says it’s not the correct token with the method websockets

const response = await axios.post(https://id.twitch.tv/oauth2/token?client_id=${clientId}&client_secret=${accessToken}&grant_type=client_credentials`);

`

I saw that websocket works with user access token, so i would have to ask to the user if it gives authorization, but i dont want that (i have been 2 days with this im so lost at this point)

The client secret is a secret it is not a token.

Websocket Eventsub only supports User Access tokens.

if you are a server solution - EventSub Webhooks (uses app access)
if you are a client side solution - EventSub websockets (users user access)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.