坚持在jQuery中调用Twitch.tv API

时间:2017-10-09 12:27:41

标签: jquery api

我一直在调用twicth.tv API。我的意思是我得到所有的频道,并可以显示它。但是当我为实时流做的时候,我收到404错误。

(document).ready(function() {
            var masterChannel = "freecodecamp";
            var followersUrl = "https://wind-bow.glitch.me/twitch-
            api / users / "+masterChannel+" / follows / channels ";
            var channelsUrl = "https://wind-bow.glitch.me/twitch-api/channels/";
            var streamsUrl = "https://wind-bow.glitch.me/twitch-api/streams/";
            $.getJSON(streamsUrl + masterChannel).done(function(live) {
                        $("#fccstatus").html(!live.stream ? "Freecodecamp is currenty 
                            OFFLINE ":"
                            Freecodecamp is currenty ONLINE ");
                        }); $.getJSON(followersUrl).done(function(followers) {
                        for (var i = 0; i < followers.follows.length; i++) {
                            var followerName = followers.follows[i].channel.name;
                            $.getJSON(channelsUrl + followerName).done(function(channel) {
                                    var channelUrl = channel.url;
                                    var channelName = channel.name;
                                    var channelUsername = channel.logo;
                                    $.getJSON(streamsUrl + channelName).done(function(live) {
                                            var status = !live.stream ? 'Offline' : 'Online';
                                            $("#followerinfo").prepend("<div class='row well a2'>" + "<div class='col-sm-
                                                4 '>"+"<img src="+channelUsername+">"+"</div>"+"<div class='
                                                col - sm - 4 abc '>"+" <
                                                a href = "+channelUrl+" > "+channelUrl+" < /a>"+"</div > "+" < div class = 'col-sm-4 
                                                abc z1 '>"+status+"</div>"+"</div>");
                                            });
                                    });
                            }
                        }); $("#online").click(function() {
                            $.getJSON(followersUrl).done(function(followers1) {
                                    for (var i = 0; i < followers1.follows.length; i++) {
                                        var followerName1 = followers1.follows[i].channel.name;
                                        $.getJSON(channelsUrl + followerName1).done(function(channel1) {
                                                var channelUrl1 = channel1.url;
                                                var channelName1 = channel1.name;
                                                var channelUsername1 = channel1.logo;
                                                $.getJSON(streamsUrl + channelName1).done(function(live1) {
                                                        var status1 = !live1.stream ? 'Offline' : 'Online';
                                                        if (status1 == "Online") {
                                                            $("#followerinfo").empty();
                                                            $("#followerinfo").prepend("<div class='row well a2'>" + "<div class='col-sm-
                                                                4 '>"+"<img src="+channelUsername1+">"+"</div>"+"<div class='
                                                                col - sm - 4 abc '>"+"<a href="+channelUrl1+">"+channelUrl1+"</a>"+"</div>"+"<div 
                                                                class = 'col-sm-4 abc z1' > "+status1+" < /div>"+"</div > ");
                                                            }
                                                        });
                                                });
                                        }
                                    });
                            })
                    });

查看代码..第一部分正在工作。但是,当我为在线点击按钮执行此操作时,它不会发生404错误。

0 个答案:

没有答案