I don't know how to combine them. I made a code by referring to the link below. Please Help me...
Android - Checking if a twitch stream is online
Is There Any Way To Check if a Twitch Stream Is Live Using Python?
setting
export const CHANNEL_NAME = ["daXXXXXX", "gmXXXXXXX"];
export const OAUTH_TOKEN = 'oauth:bn1rXXXXXXXXXXXXXXXXX';
export const CLIENT_ID = 'bxqtXXXXXXXXXXXXXXXXX';
export const BOT_USERNAME = 'gaXXXXt';
my code
async function test2() {
var theUrl = `https://api.twitch.tv/kraken/streams/${CHANNEL_NAME[0]}`
var headers = {
"Client-ID": CLIENT_ID
};
fetch(theUrl, headers).then(data =>{
console.log(data)
})
}
test2()
debug data
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 5,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
disturbed: false,
error: null
},
[Symbol(Response internals)]: {
url: 'https://api.twitch.tv/kraken/streams/#daXXXXXX',
status: 400,
statusText: 'Bad Request',
headers: Headers { [Symbol(map)]: [Object: null prototype] },
counter: 0
}
}
The twitch kraken
has been decommissioned, you need to use the helix
api instead.
async function isStreamerLive(username) {
const theUrl = `https://api.twitch.tv/helix/streams?user_login=${username}`
const headers = {
"Client-Id": CLIENT_ID,
"Authorization": OAUTH_TOKEN
};
const response = await fetch(theUrl, headers);
const data = await response.json();
return data?.data?.find(s => s.user_login === username.toLocaleLowerCase())
}