简体   繁体   English

如何使用JQuery访问Twitch流

[英]How to use JQuery to Access Twitch streams

Alright, so I want to access each twitch stream name in an array, then push to an html div a link to each online stream and its logo. 好吧,所以我想访问数组中的每个抽搐流名称,然后将指向每个在线流及其徽标的链接推到html div。 The problem is that I just don't know how to do this, or where to begin really. 问题是我只是不知道该怎么做,或者真正从哪里开始。 I've read the documentation about twitch api calls, but either I'mvbeing thick or I'm missing something else. 我已经阅读了有关twitch api调用的文档,但是我很胖或者缺少其他东西。

This is my javascript: 这是我的javascript:

var possibleChannels= ["storbeck", "terakilobyte", "habathcx","RobotCaleb","comster404","brunofin","thomasballinger","noobs2ninjas","beohoff"];

possibleChannels.forEach(function(element){
$.getJSON('https://api.twitch.tv/kraken/streams/' + element, 
function(channel){
if (channel["stream"] == null) { 
   ($"All").append("<p>Paragraph</p>");
} 
else {
   ($"All").append("<p>Paragraph</p>");   
}
});
}

The "paragraph" text is just to see if I can actually write text to the html document, and "All" is a div element I have set up. “段落”文本只是看我是否可以实际将文本写入html文档,而“全部”是我设置的div元素。 Am I accessing the twitch stream correctly? 我是否正确访问了抽搐流? Any help is appreciated, even if it is the "go to google and type this in" kind of help. 感谢任何帮助,即使它是“转到Google并键入此内容”的帮助。

I tried your example but was not able to get it to work correctly until I put a '?callback=?' 我尝试了您的示例,但是直到我输入'?callback =?'后,它才能正常工作。 as suggested in another post here . 正如在另一篇文章中建议的那样 Here is a working example: 这是一个工作示例:

var possibleChannels= ["storbeck", "terakilobyte", "habathcx","RobotCaleb","comster404","brunofin","thomasballinger","noobs2ninjas","beohoff"];

possibleChannels.forEach(function(name){
$.getJSON('https://api.twitch.tv/kraken/streams/' + name + '?callback=?', 
    function(channel){
        if (channel["stream"] == null) {
            $("#all").append("<p>" + channel._links.self + "</p>");
        } 
        else {
           $("#all").append("<p>Fail</p>");   
        }
    });
});

You also have the issue with ($"All) as pointed out by Scheda. I used an id tag in the JSFiddle example. 还有Scheda指出的($"All)问题。我在JSFiddle示例中使用了id标记。

JSFiddle: http://jsfiddle.net/rnhm3xfL/ JSFiddle: http : //jsfiddle.net/rnhm3xfL/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM