【发布时间】:2021-12-30 14:49:40
【问题描述】:
我正在尝试从 Twitch 获取 oauth 令牌,并使用以下代码:
import dotenv from 'dotenv';
dotenv.config();
import fetch from 'node-fetch';
let creds = {
client_id:process.env.CLIENT_ID,
client_secret:process.env.CLIENT_SECRET,
grant_type:"client_credentials"
};
let request = {
method:'POST',
header:{ "Content-Type": "application/json" },
body:creds
};
console.log(request);
fetch(process.env.AUTH_URL,request)
.then (res => res.text())
.then (text => console.log(text))
在适当的情况下使用我的秘密和客户 ID。但是它不断返回:
{"status":400,"message":"missing client id"}
我做错了什么?
【问题讨论】:
-
请确认:
console.log(process.env.CLIENT_ID)中有内容。如果是,请使用环境变量NODE_DEBUG=http运行您的程序以查看发出的请求。
标签: javascript node.js twitch node-fetch twitch-api