Node JS和Coinbase

问题描述 投票:0回答:3

我正在尝试将Coinbase与Node Js集成,但我无法执行教程页面上给出的代码。我的代码是

`var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
  });
});`

我得到以下错误:

accounts.forEach(account => {^ typeError:无法读取属性'forEach'为null期待您的回答!谢谢!

javascript node.js coinbase-api
3个回答
2
投票

错误很明显:accounts等于null。在使用err之前,你应该检查accounts中的内容


0
投票

你好,你可以这样使用

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.id );
  });
});

0
投票

您可以尝试使用不同的API密钥并检查密钥是否已启用。

var Client = require('coinbase').Client;

var client = new Client({
  'apiKey': 'API KEY',
  'apiSecret': 'API SECRET'
});

client.getAccounts({}, function (err, accounts) {
  accounts.data.forEach(function (acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.id);
  });
});

帐户也会返回大量信息,但我们正在查看数据块。有关getAccounts()调用的完整示例响应,请参阅Coinbase API v2文档 - https://developers.coinbase.com/api/v2?javascript#account-resource如果可行,请告诉我们。祝好运!

© www.soinside.com 2019 - 2024. All rights reserved.