【发布时间】:2021-06-30 02:39:09
【问题描述】:
这里完全是菜鸟程序员(最初是一名老派机械工程师)。
在网上学习了一些 Javascript 课程后,我想我可以尝试在 Google Sheet 上构建一个简单的脚本。 我的项目计划是有一个脚本来通过他们的API 自动跟踪我在Luno.com(cryptoexchange)上的所有交易。 他们的API documentation is here。
我试图使用List Transactions 来填充我的电子表格中的所有历史交易,但我遇到了authenticate UrlFetchApp.fetch(url) endpoint 访问请求
编辑:您应该重新考虑公开分享您的身份验证信息。我删除了它。
下面是我的 Code.gs 脚本:
function importStatementLuno() {
var ss = SpreadsheetApp.getActiveSpreadsheet(); //get active spreadsheet (bound to this script)
var url = 'https://api.luno.com/api/1/accounts/xxx/transactions'; //api endpoint as a string
var response = UrlFetchApp.fetch(url,{'muteHttpExceptions': false}); // get api endpoint
var json = response.getContentText(); // get the response content as text
var lunodata = JSON.parse(json); //parse text into json
Logger.log(lunodata);
我的 fetch 响应给了我这个错误:
异常:https://api.luno.com 的请求失败,返回代码 401。截断的服务器响应:未经授权 (使用 muteHttpExceptions 选项检查完整响应)
我一辈子都无法理解他们的文档!我不确定是否实际上有不同的表达式用于向他们的服务器提供身份验证密钥(他们明确提到他们在Get Started documentation 中更好地支持 Go) 我希望这里有人可以帮助我指出我哪里出错了。
【问题讨论】:
-
您不应在此论坛上分享私人信息。如果您提供的身份验证信息允许其他人访问您的帐户,您可能应该考虑立即更改它。
-
嗨@Zann,你能尝试下面答案中提到的基本身份验证吗?
标签: javascript google-apps-script