hi, new here using the twitch api, starting from an example in javascript i made it work and get data from the /kraken/users/ , /kraken/channels/ and /kraken/stream/ requests , using something like this :
var clientID = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
var userID = 'yyyyyyy';
var twitch_user_api = new XMLHttpRequest();
twitch_user_api.open('GET', 'https://api.twitch.tv/kraken/users/' + userID + '?client_id=' + clientID, true);
twitch_user_api.setRequestHeader('Accept', 'application/vnd.twitchtv.v5+json');
twitch_user_api.onload = function() {
var data = JSON.parse(twitch_user_api.responseText);
if (data) {
document.getElementById('twitch_1').innerHTML = 'stream bio : ' + data.bio;
} else {
document.getElementById('twitch_1').innerHTML = '----';
}
}
twitch_user_api.send(null);
now, i have this problem when i want to get the user id from the user name as described in https://dev.twitch.tv/docs/v5/guides/using-the-twitch-api/ , the code i have so far to test is : ( using the example from that link, later gonna replace that for a user using php and a form, clientID is the same value from the others working examples i have , and so far i understand i don’t need the Aouth there, right?)
var clientID = 'xxxxxxxxxxxxxxxxx';
var twitch_user_api = new XMLHttpRequest();
twitch_user_api.open('GET', 'https://api.twitch.tv/kraken/users?login=dallas,dallasnchains'+ '?client_id=' + clientID , true );
twitch_user_api.setRequestHeader('Accept', 'application/vnd.twitchtv.v5+json');
twitch_user_api.onload = function() {
var data = JSON.parse(twitch_user_api.responseText);
if (data) {
document.getElementById('twitch_1').innerHTML = 'user id : ' + data.users[0]._id ;
} else {
document.getElementById('twitch_1').innerHTML = 'no user';
}
};
twitch_user_api.send(null);
from what i understand of that json response i should use data.users[0]._id to get what i need (later when i have only 1 name is going to be 0 too? ), but nothing is displaying
any idea in the right direction to make this work? i would like to keep using only just js , not php or something else, thanks in advance!