【发布时间】: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