Currently developing a Node bot and working on a function to post in Discord whenever I go live.
From what I have read, the only way to get a channel ID is doing the ‘users?login’ method, such as this:
function twitchLiveCheck(){
let options = {
hostname: 'api.twitch.tv',
family: 4,
pathname: '/kraken/users?login=darkswordsmantv',
headers: {
'Accept': 'application/vnd.twitchtv.v5+json',
'Client-ID': '~~~~'
}
}
console.log('sending twitch request');
https.get(options, function(res){
console.log('response received');
let data;
res.on('data', function(chunk){
console.log('adding data');
data += chunk;
});
res.on('end', function(){
console.log('data stream ended');
try {
const parsedData = data;
console.log(parsedData);
} catch (e) {
console.error("error: " + e.message);
}
});
});
}
This returns an HTML response of the following. I originally had const parsedData = JSON.parse(data)
, but that wasn’t working for obvious reasons. This also includes the console messages:
sending twitch request
Server is listening on port: 1337
response received
adding data
data stream ended
undefined<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
From my understanding it’s supposed to return a JSON response with my client ID and other information.
I’m just trying to get information to tell if I’m live so I can send a Discord message.
I am using express v5.6.0 and Node v8.9.3.