gpt4 book ai didi

node.js - Swagger 客户端 API key 认证

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:15 26 4
gpt4 key购买 nike

我必须使用我的 Api key 向 Bitmex API 进行身份验证,但我遇到了这个错误

无法连接:类型错误:无法读取未定义的属性“add”

'use strict';
var SwaggerClient = require("swagger-client");
var _ = require('lodash');
var BitMEXAPIKeyAuthorization = require('./lib/BitMEXAPIKeyAuthorization');

require('dotenv').config();

new SwaggerClient({
// Switch this to `www.bitmex.com` when you're ready to try it out for real.
// Don't forget the `www`!
url: 'https://testnet.bitmex.com/api/explorer/swagger.json',
usePromise: true
})
.then(function(client) {
//console.log(client);
// Comment out if you're not requesting any user data.
client.clientAuthorizations.add("apiKey", new BitMEXAPIKeyAuthorization(process.env.BITMEX_API_KEY, process.env.BITMEX_API_SECRET));

// Print client capabilities
//

})
.catch(function(e) {
console.error("Unable to connect:", e);
})

Nodejs 连接器:https://github.com/BitMEX/api-connectors

最佳答案

您正在使用最新版本的客户端,它不会以这种方式进行授权:https://github.com/swagger-api/swagger-js/blob/903569948d5a5c718d7b87d6832a672de4e76afc/docs/MIGRATION_2_X.md#authorizations

new SwaggerClient({
// Switch this to `www.bitmex.com` when you're ready to try it out for real.
// Don't forget the `www`!
url: 'https://testnet.bitmex.com/api/explorer/swagger.json',
usePromise: true,
authorizations: {
apiKey: new BitMEXAPIKeyAuthorization(process.env.BITMEX_API_KEY, process.env.BITMEX_API_SECRET)
}
})
.then(client => {
// Do whatever with client
})
.catch(function(e) {
console.error("Unable to connect:", e);
})

关于node.js - Swagger 客户端 API key 认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48013836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com