javascript twitch api获取状态不起作用

时间:2019-06-26 20:45:02

标签: javascript html

抽动api的请求不适用于您的帐户

我尝试使用朋友帐户及其有效的客户ID

function actuStream(){
    $.getJSON('https://api.twitch.tv/kraken/streams/tiwabs&client_id=fgg8ys5fj5eg2founn7t77r3rby9vs', function (channel) {
        viewersNumber = document.getElementById('viewersnumber');
        viewers = document.getElementById('viewers');
        streamTitle = document.getElementById('streamtitle');
        if (channel['stream'] === null) {
            viewersNumber.innerHTML = '<span class="offline">HORS-LIGNE</span>';
            viewers.innerHTML = '';
            streamTitle.innerHTML = '';
        } else {
            viewersNumber.innerHTML = channel['stream']['viewers'];
            viewers.innerHTML = 'VIEWERS';
            streamTitle.innerHTML = '<p class="streamtitle"><span>&Eacute;MISSION:&nbsp;&nbsp;</span> ' + channel['stream']['channel']['status'] + '</p>';
        }
        /*
        $.getJSON(channel['stream']['channel']['_links']['subscribtions'], function(subs){
            alert(subs['_total']);
        });*/

    });
    if (count !== 0){
        if(min%3) ga('send', 'event', 'time', 'tracking', 'seconds', count);
        count += 60;
    }else{
        ga('send', 'event', 'time', 'tracking', 'seconds', count);
        count = 60;
    }
    min++;
}
<div id="lefttheatre">
 <div class="toplive">
  <a id="theatre" onclick="theatre()" class="show-for-medium">Mode Th&eacute;&acirc;tre</a>
  <div class="viewersnumber" id="viewersnumber">
  </div>
  <div class="viewers" id="viewers">
  </div>
 </div>
 <div id="streamtitle"></div>
  <iframe id="stream" src="https://player.twitch.tv/?channel=tiwabs" frameborder="0" scrolling="no" height="100%" width="100%" allowfullscreen="true"></iframe>
 </div>

当我在Google中输入链接时,出现此错误 {“错误”:“错误请求”,“状态”:400,“消息”:“参数\“ id \”格式错误:该值必须与正则表达式/ ^ [0-9] + $ /“}相匹配

我尝试使用另一个帐户和客户ID,并且效果很好

1 个答案:

答案 0 :(得分:0)

正则表达式仅用于整数:https://regexr.com/4gglh

您的ID是字母数字,只需要数字即可。

另外,请参考新文档:https://dev.twitch.tv/docs/api/,其中您的ID应该有效。