Hello, this morning my code was working very well but now, i am getting 401 error.
This is the code:
const callAJAX = (props) => {
const url = props.url,
method = props.method || "GET",
type = props.type || "JSON",
header = props.header
;
return new Promise(waitForResult => {
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
type === "text"
? waitForResult(this.response)
: waitForResult(JSON.parse(this.response))
;
}
};
if (method === "GET") {
xhttp.open("GET", url, true);
for (const key in props.header) {
xhttp.setRequestHeader(key, header[key]);
}
xhttp.send();
}
});
};
const AJAXProps = {
url: "https://api.twitch.tv/helix/streams?first=20",
header: {"Client-ID": "cpfxuznsjx64e2k6h58ujmmwtsqr29"}
};
var users = ["esl_csgo"];
var user_login = users.join('&user_login=');
callAJAX(AJAXProps).then(allUser => {
AJAXProps.url = `https://api.twitch.tv/helix/streams?user_login=${user_login}`;
callAJAX(AJAXProps).then(onlineUsers => {
console.log(onlineUsers);
});
});
Thank you