weixin_33691598 2018-03-15 19:54 采纳率: 0%
浏览 170

新的TwitchTV API调用

I am a beginner to programming and for a challenge I need to get the status (Streaming live/Off-line) for a given number of channels.

I wrote an ajax request but I am still getting 401 as a response. Below my code and a screen shot of the response.

I have even made the token request as async: falseto make sure the token is back before triggering the API call

$("document").ready(function() {

var aoathToken = $.ajax({
    type: "POST",
    url: "https://id.twitch.tv/oauth2/token?client_id=MYCLIENTID&client_secret=MYSECRET&grant_type=client_credentials",
    error: function() {
        console.log("Check your request!!")
    },

    success: function(token) {
        console.log(token);
    }
})

$.ajax({
    type: "GET",
    url: "https://api.twitch.tv/helix/streams?user_id=freecodecamp",
    contentType: ('application/x-www-form-urlencoded; charset=UTF-8'),
    crossDomain: true,
    header: {
        "Access-Control-Allow-Origin": "*",
        "Client-ID": "MY CLIENT ID",
        "Authorization": "Bearer " + aoathToken,
    },
    data: {"user_login": "myUserID"},
    dataType: "json",
    success: function(json) {
        console.log(JSON.stringify(json, null, 2));
    },
    error: function(json) {
        window.alert(json.status + " " + json.message);
    },
})

API response

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Centos7 / PETGEM
    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗