I see, sorry about that. This is the JS code that access the twitch API on my node js server:
const req = https.request(url, options, function(response){
console.log( "1. statusCode:", response.statusCode);
// console.log("2. headers:", response.headers);
response.on("data", function(data){
let myObj = data;
AT = JSON.parse(myObj).access_token;
// process.stdout.write(data);
console.log("---------------------------")
});
});
req.on('error', (e) => {
console.error("error 1: "+ e);
console.log("passed through here");
});
req.end();
// GET requests for channel and channel clips
app.get("/", function(req, res){
const optionals = {
method: "GET",
dataType: 'json',
headers: {
"Client-ID": process.env.CLIENT_ID,
Authorization: "Bearer " + AT,
Accept: "application/vnd.twitchtv.v5+json"
}
}
https.get("https://api.twitch.tv/helix/users?login=veeetag", optionals, function(response){
console.log('3. statusCode:', response.statusCode);
// console.log("4. headers:", response.headers);
response.on("data", (d) => {
let channel = JSON.parse(d);
console.log(channel);
userId = channel.data[0].id;
console.log('--------------------------');
// process.stdout.write(d);
});
}).on("error", (e) => {
console.error("error 2: " + e);
});
// other url = 'https://api.twitch.tv/kraken/clips?id=' + userId
setTimeout(() => {
https.get('https://api.twitch.tv/helix/clips?broadcaster_id=' + userId, optionals, function(resp){
console.log('3. statusCode:', resp.statusCode);
// console.log("4. headers:", resp.headers);
resp.on('data', (da) => {
// let clips = JSON.parse(da);
// console.log(clips);
process.stdout.write(da);
});
}).on("error", (e) => {
console.error("error 2: " + e);
});
}, 1000);