I am working on something for my own website to display a list of members of a team that someone is in.
The problem I am having is getting an array of members for a Team.
So far this is what my code looks like (sorry if it looks a bit messy)
var ar = [];
var names = [];
var team = 'buildguild';
$.ajax({
url: 'https://api.twitch.tv/api/team/'+team+'/all_channels.json',
type: 'GET',
dataType: 'json',
headers: {
'Access-Control-Allow-Orgin':'*'
},
success: function(data) {
console.log(data);
for (var i = 0; i < data.channels.length; i++) {
names.push(data.channels[i].channel.display_name);
ar[data.channels[i].channel.display_name] = data.channels[i].channel;
$('.members').append('<div><span style="margin-left:5px;">Name: '+data.channels[i].channel.display_name+'</span><br><span style="margin-left:5px;"> Viewers: '+data.channels[i].channel.current_viewers+'</span><br><span style="margin-left:5px;"> Status: '+data.channels[i].channel.status+'</span></div>');
}
console.log(ar);
console.log(names);
},
error: function(err) {
console.log(err)
}
})
When I try to get the array of members in the Team I get this error:
XMLHttpRequest cannot load https://api.twitch.tv/api/team/buildguild/all_channels.json. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.
I’ve searched for anything that could possibly help me but nothing that I have found has for me worked.
I’ve also tried to do this call via XMLHttp request and it still didn’t work.
If someone could help me that would be amazing.