如何使用JQuery访问Twitch流 [英] How to use JQuery to Access Twitch streams

查看:123
本文介绍了如何使用JQuery访问Twitch流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想访问数组中每个抽搐流的名称,然后将指向每个在线流及其徽标的链接推到html div中.问题是我只是不知道该怎么做,或者真正从哪里开始.我已经阅读了有关twitch api调用的文档,但是我太胖了或者我错过了其他东西.

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. 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.

这是我的javascript:

This is my 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>");   
}
});
}

段落"文本只是看我是否可以实际将文本写入html文档,而全部"是我设置的div元素. 我是否正确访问了抽搐流? 感谢任何帮助,即使它是转到Google并键入此内容"的帮助.

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. 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.

推荐答案

我尝试了您的示例,但是直到我输入'?callback =?'后,该示例才能正常工作. 如此处另一篇文章中所建议.这是一个工作示例:

I tried your example but was not able to get it to work correctly until I put a '?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>");   
        }
    });
});

您也遇到了Scheda指出的($"All)问题.我在JSFiddle示例中使用了id标记.

You also have the issue with ($"All) as pointed out by Scheda. I used an id tag in the JSFiddle example.

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

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

这篇关于如何使用JQuery访问Twitch流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆