jQuery will automatically handle the callback. Just make sure that “API-key” is your client ID. You’re also adding an extra “?” in the query string will not work correctly.
This is the faulty URL that you are creating:
https://api.twitch.tv/kraken/streams/?channel=ivelios_christopher,esl_sc2?client_id=API-key&callback=?
When you’re using the multiple channel endpoint, you cannot use the data.stream === null trick. That’s just for one channel using the stream/<channel> endpoint. Reference.
You may be better served with code like this:
var clientID = 'client ID string';
var channelList = [ 'ivelios_christopher', 'esl_sc2' ];
var baseKraken = 'https://api.twitch.tv/kraken/';
var endpoint = 'streams';
$.getJSON(
baseKraken + endpoint
{
client_id: clientID,
api_version: 'v5',
channel: channelList
}
)
.done(function(data) {
if(data._total > 0) {
chrome.browserAction.setBadgeText({text: 'On'});
}
});
Or as a simple function:
var clientID = 'client ID string';
var baseKraken = 'https://api.twitch.tv/kraken/';
function getKrakenAPI(endpoint, data, method) {
return $.ajax({
url: baseKraken + endpoint,
method: method,
data: data,
dataType: 'json',
headers: {
'Client-ID': clientID,
Accept: 'application/vnd.twitchtv.v5+json'
}
});
}
getKrakenAPI(
'streams',
{
channel: [ 'ivelios_christopher', 'esl_sc2' ]
}
)
.done(function(data) {
if(data._total > 0) {
chrome.browserAction.setBadgeText({ text: 'On' });
}
});