Hi, I am getting this error when trying to subscribe to any events.
Here is the code I am using for the subscription:
function subscribeToEventSub(event_name: string, version: number, condition: any = {}, app_token: string, session_id: string): void {
fetch('https://api.twitch.tv/helix/eventsub/subscriptions', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + app_token,
"Client-Id": "<APP CLIENT ID>",
"type": event_name,
"version": version.toString(),
"condition": JSON.stringify(condition), // {"broadcaster_user_id": user_id}
"transport": JSON.stringify({
"method": "websocket",
"session_id": session_id
})
}
})
...
}
app_token
is obtained using this piece of code:
async function getTwitchAppAccessToken(): Promise<string> {
let req = await fetch(`https://id.twitch.tv/oauth2/token`
+ `?client_id=<APP CLIENT ID>`
+ `&client_secret=<APP CLIENT SECRET>`
+ `&grant_type=client_credentials`,
{
method: 'POST'
});
let resp = await req.json();
return resp["access_token"]; // pardon the lack of error checking
}
It is very likely that my error is linked to this:
If you use WebSockets to receive events, the request must specify a user access token
So I also tried replacing the Authorization
token with one gotten from the implicit grant flow.
Here is the url I am using (I successfully manage to get the asked tokens, no problems here):
`https://id.twitch.tv/oauth2/authorize`
+ `?client_id=<APP CLIENT ID>`
+ `&redirect_uri=http://localhost:3000/callback`
+ `&response_type=token+id_token`
+ `&scope=channel:read:subscriptions+moderator:read:followers+bits:read+openid`
But with the Authorization
token set to use the one from the implicit grant flow, I get another error:
The ID in the Client-Id header must match the client ID in the access token.
What am I doing wrong ?