Greetings!
I am trying to make an endpoint, which will check if a specific user is streaming. I need it to return true/false. Here is my code:
// is streaming endpoint
app.get("/is-streaming/:username", async (req, res) => {
const twitchUsername = req.params.username;
const twitchApiEndpoint = `https://api.twitch.tv/helix/streams?user_login=${twitchUsername}`;
const twitchApiHeaders = {
"Client-ID": `client-id is here....`,
};
try {
const response = await fetch(twitchApiEndpoint, {
headers: twitchApiHeaders,
});
const data = await response.json();
if (data.data && data.data.length > 0) {
res.json({ isStreaming: true });
console.log(data);
} else {
res.json({ isStreaming: false });
console.log(data);
}
} catch (error) {
console.error(error);
res.status(500).send({ error: "Error checking Twitch stream status" });
}
});
The client-id is hardcoded for tests on localhost. console.log(data) gives me this:
{
error: 'Unauthorized',
status: 401,
message: 'OAuth token is missing'
: }
But as I understood - I need to pass either the client-id, either the oauth token. And I believe i am passing the client-id correctly (got it from twitch dev - applications…). Any suggestions?