我正在使用上面的代码与coinbase api进行交互。它工作正常,但直到最近它返回一个错误。这是代码
var coinbase = require('coinbase');
var mysecret = 'apisecret'
var mykey = 'apikey'
var client = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});
client.getAccounts({}, function(err, accounts) {
if (err)throw err;
console.log(accounts)
});
这是我得到的错误
if (err)throw err
^
Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
at TLSSocket.emit (events.js:198:13)
at TLSSocket._finishInit (_tls_wrap.js:636:8)
Coinbase已更新SSL证书,为避免此问题,创建新客户端时需要将strictSSL
设置为false
const coinbase = require('coinbase')
const mysecret = 'apisecret'
const mykey = 'apikey'
const client = new coinbase.Client({ apiKey: mykey, apiSecret: mysecret, strictSSL: false })
client.getAccounts({}, function(err, accounts) {
if (err) throw err
console.log(accounts)
})
或通过新证书
const coinbase = require('coinbase')
const mysecret = 'apisecret'
const mykey = 'apikey'
const caFile = fs.readFileSync('./caFileLocation')
const client = new coinbase.Client({ apiKey: mykey, apiSecret: mysecret, caFile })
client.getAccounts({}, function(err, accounts) {
if (err) throw err
console.log(accounts)
})