2017-05-30 85 views
0

我想将Coinbase与Node Js集成,但我无法执行教程页上给出的代码。我的代码是Node JS和Coinbase

`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); 
    }); 
});` 

我得到t时的以下错误:

accounts.forEach(account => { ^ typeError: Cannot read property 'forEach' of null Looking forward to your answer! Thanks!

+0

添加'if(err){console.log(err); }'在foreach循环之前调试错误。 –

+0

谢谢。我得到一个ReferenceError:err没有定义 – donfrigo

回答

2

的错误是明显的:accounts等于空。您应该检查什么在erraccounts

+0

谢谢,我也遇到了checkng err困难。由于没有定义err,我得到一个参考错误。如何克服它?谢谢。 – donfrigo

+0

就在'accounts.forEach'之前,加上'if(typeoferr!=='undefined'){console.log(err);}' –

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); 
    }); 
}); 

此外,帐户还会返回很多信息,但我们正在查看数据块。请参阅Coinbase API v2文档以获取getAccounts()调用的完整示例响应 - https://developers.coinbase.com/api/v2?javascript#account-resource 让我们知道这是否可行。祝你好运!