【发布时间】:2017-12-19 16:05:12
【问题描述】:
为了继续使用 Google Apps 脚本构建 Google SpreadSheet,我已经完成了获取 Bittrex 和 Poloniex 余额的工作,但无法使用 Cryptopia。
这是我与 Bittrex Map JSON objects array to strings 斗争的链接
这里是官方API链接:https://www.cryptopia.co.nz/Forum/Thread/256
这里有一些例子:
- https://www.cryptopia.co.nz/Forum/Thread/262
- https://github.com/Coac/cryptopia.js/blob/master/index.js
- https://github.com/sigwo/node-cryptopia/blob/master/cryptopia.js
这是我的代码,出现“无效的授权标头”错误:
// Get Cryptopia balances
var key = keys.getRange("B4").getValue();
var secret = keys.getRange("C4").getValue();
var baseUrl = 'https://www.cryptopia.co.nz/api/';
var command = "GetBalance";
var url = baseUrl + command;
var signature = key + "POST" + encodeURIComponent(url).toLowerCase() + nonce;
var hmacsignature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256,signature,secret);
var header_value = "amx " + key + ":" + hmacsignature + ":" + nonce;
var headers = { 'Authorization': header_value, 'Content-Type':'application/json; charset=utf-8' };
var options = {
method: 'POST',
headers: headers
};
var response = UrlFetchApp.fetch("https://www.cryptopia.co.nz/api/GetBalance", options);
var json = JSON.parse(response.getContentText());
}
【问题讨论】:
标签: authentication google-apps-script authorization