【问题标题】:twitch.js fetch error: ClientID is missingtwitch.js 获取错误:缺少 ClientID
【发布时间】:2021-09-15 13:43:02
【问题描述】:

我正在尝试通过 Twitch.js 使用 twitch API (helix)。我似乎找不到使用 API 的方法。首先尝试仅使用令牌但不起作用,尝试使用 Twitch Applications 的 clientID 和令牌但效果不佳。除了这个页面(https://twitch-js.netlify.app/classes/api.html)之外,我找不到任何关于 const api 正常工作所需的参数,这似乎已经过时,因为我显然需要 clientID 和 oAuth 这是我的代码:

const { Chat, ChatEvents, Api } = require("twitch-js");

const username = xxxxxx;
const token = xxxxxxxx;
const channel = xxxxxx;
const clientID = xxxxxx;

const run = async () => {
    const chat = new Chat({
      username,
      token
    });

    const api = new Api({
        clientID,
        token
    });
  
    await chat.connect();
    await chat.join(channel);
  
    //API test ↓

    api.get('bits/leaderboard', { search: { user_id: 'xxxxx' } }).then(response =>{
        console.log(response);
    })

run();

这是我的错误:

[1631712611142] ERROR (TwitchJS/Api/10720 on PC): GET https://api.twitch.tv/helix/bits/leaderboard (334ms)
(node:10720) UnhandledPromiseRejectionWarning: FetchError: [TwitchJS] Client ID is missing
    at D:\Documents\Code\anti bot\node_modules\twitch-js\lib\utils\fetch\fetch.js:90:31
    at step (D:\Documents\Code\anti bot\node_modules\twitch-js\lib\utils\fetch\fetch.js:44:23)
    at Object.next (D:\Documents\Code\anti bot\node_modules\twitch-js\lib\utils\fetch\fetch.js:25:53)
    at fulfilled (D:\Documents\Code\anti bot\node_modules\twitch-js\lib\utils\fetch\fetch.js:16:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

【问题讨论】:

    标签: node.js twitch twitch-api


    【解决方案1】:

    因为你有一个错字。

    clientID > clientId

    你只需要令牌或客户端ID

    // With a token ...
    const token = 'cfabdegwdoklmawdzdo98xt2fo512y'
    const { api } = new TwitchJs({ token })
    
    // ... or with a client ID ...
    const clientId = 'uo6dggojyb8d6soh92zknwmi5ej1q2'
    const { api } = new TwitchJs({ clientId })
    

    查看twitch-js github 了解更多示例

    【讨论】:

    • 我没想到更改变量名实际上会起作用!谢谢!!!
    猜你喜欢
    • 2018-01-02
    • 2015-08-11
    • 2014-05-22
    • 2018-01-20
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多