首页 > 解决方案 > 我对新的 Twitch API 有一些疑问

问题描述

我为我的 twitch 频道创建了自己的浏览器扩展。

我使用 Twitch Kraken API 编写了 javascript 扩展,但它已被更改。

新的 Twitch API 是“ https://api.twitch.tv/helix/streams?game_id=33214

我替换了代码中的 API,但扩展始终显示在线状态。

    xhr.open('GET', this.API_URL_STREAM, true)

    xhr.setRequestHeader('Accept', 'application/vnd.twitchtv.v5+json')
    xhr.setRequestHeader('Client-ID', this.CLIENT_ID)

    xhr.onreadystatechange = e => {
        if (xhr.readyState == 4 && xhr.status == 200) {
            const body = xhr.responseText
            let json = {}

            try {
                json = JSON.parse(body)
            } catch (e) {
                console.info(e, xhr.responseText)
            }

            this.handle_response(json)
        }
    }
    xhr.send(null)
}

我没有错误信息。我的直播总是处于在线状态,但我没有直播。

标签: browsertwitch-api

解决方案


推荐阅读