javascript - 尝试访问 Fortnite-API 时出现 UnhandledPromiseRejectionWarning?

标签 javascript node.js api

我正在尝试使用node.js 访问fortnite API。我已按照文档中指定的方式进行了所有设置,但遇到了以下几个错误:

Fortnite-API - Credentials Params OK
(node:3036) UnhandledPromiseRejectionWarning: #<Object>
(node:3036) UnhandledPromiseRejectionWarning: Unhandled promise 
rejection. This error originated either by throwing inside of an async 
function without a catch block, or by rejecting a promise which was not 
handled with .catch(). (rejection id: 1)
(node:3036) [DEP0018] DeprecationWarning: Unhandled promise rejections 
are deprecated. In the future, promise rejections that are not handled 
will terminate the Node.js process with a non-zero exit code.

到目前为止我的代码是:

const Fortnite = require("fortnite-api");

let fortniteAPI = new Fortnite(
[
    "redacted",
    "redacted",
    "redacted",
    "redacted"  
],
{
    debug: true
}
);

fortniteAPI.login().then(() => {
fortniteAPI
    .checkPlayer("x got", "pc")
    .then(stats => {
        console.log(stats);
    })
    .catch(err => {
        console.log(err);
    });
});

这是我第一次自己搞乱node.js,所以我真的不知道这些错误是怎么回事。我曾尝试用谷歌搜索这些错误,但所有的解释要么超出了我的理解范围,要么看起来像是用不同的语言编写的。

编辑:对于稍后查看此内容的任何人,我的错误是由于在我的帐户上启用了 2FA(双因素身份验证)引起的。您将必须完全禁用它。另外,稍后会发现启动游戏获取 Fortnite API key 后 Fiddler 4 将无法工作。我在谷歌搜索了几个小时后发现了一些,所以我将它们留在这里:

客户端启动器 token :MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=

《堡垒之夜》客户端 token :ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ=

(请务必包含“=”)

最佳答案

您能否在登录 promise 中添加一个捕获,如下所示。看看你是否能够捕获错误。

fortniteAPI.login().then(() => {
fortniteAPI
.checkPlayer("x got", "pc")
.then(stats => {
    console.log(stats);
})
.catch(err => {
    console.log(err);
});
}).catch((error)=>{console.log('error at login-->',error)});

关于javascript - 尝试访问 Fortnite-API 时出现 UnhandledPromiseRejectionWarning?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53002422/

相关文章:

javascript - 通过 $_GET 将 URL 变量传递给 Javascript

node.js - 如何 Dockerize 前端应用程序以与已经 dockerized api 应用程序通信

python - 是否有用于 python pandas 的 C/C++ API?

javascript - Power BI API 身份验证

api - 如何将变量值从一个 Postman 环境获取到另一个环境

javascript - 查找来自 Firefox 扩展的所有 URL 请求

javascript - Object.defineProperty 不改变元素的属性

javascript - 没有观察的缓存 View

javascript - 在 Node 中设置日期时间/计时器

node.js - 如何将 NPM 包迁移到组织 @scope