我正在做Freecodecamp Twitch TV项目,在那里我展示了9个流媒体是否在线。我使用这个数组来存储拖缆:
Codepen:https://codepen.io/Mike-was-here123/pen/MOmKzO
var streamers = [
"ESL_SC2",
"OgamingSC2",
"cretetion",
"freecodecamp",
"storbeck",
"habathcx",
"RobotCaleb",
"noobs2ninjas"
];
我使用这两个API,我使用了for loop
,我稍后会解释。
频道/流媒体详情:
"https://wind-bow.gomix.me/twitch-api/channels/"+streamers[i]+"?callback=?"
流细节(检查他们的流媒体)
"https://wind-bow.gomix.me/twitch-api/streams/"+streamers[i]+"?callback=?"
我使用此代码访问这些API
for (var i = 0; i < streamers.length; i++) {
var streamStatusApi =
"https://wind-bow.gomix.me/twitch-api/streams/" +
streamers[i] +
"?callback=?";
var channelApi = "https://wind-bow.gomix.me/twitch-api/channels/" +
streamers[i] +
"?callback=?";
$.getJSON(streamStatusApi, function(data) {
$.getJSON(channelApi, function(data2) {
if(data.stream == null) {
// here i pushed something into the html based on stream status
}
else if (data.stream == true) {
// here i pushed something into based on stream status.
}
});
}); // $.getJSON for stream status
} // for loop
那么为什么只有noobs2ninjas
的流状态显示在html上?基本上是数组中的姓氏。