我正在尝试使用以下代码连接到我的API,我使用节点filename.html运行API attunication登录javascript代码。它显示以下错误。 Binance API Doc。拜托,有什么建议吗?
SyntaxError: Unexpected token '<'
←[90m at wrapSafe (internal/modules/cjs/loader.js:1054:16)←[39m
←[90m at Module._compile (internal/modules/cjs/loader.js:1102:27)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:986:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:879:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m
API登录代码:<html>
<script type="text/javascript" src="crypto-js.js"></script>
<script>
var burl = 'https://api.binance.com';
var endPoint = '/api/v3/account';
var dataQueryString = 'recvWindow=20000×tamp=' + Date.now();
var keys = {
'akey' : 'xxxxxxxx',
'skey' : 'xxxxxxxx'
}
var signature = CryptoJS.HmacSHA256(dataQueryString ,keys['skey']);
var ourRequest = new XMLHttpRequest();
var url = burl + endPoint + '?' + dataQueryString + '&signature=' + signature;
ourRequest.open('GET', url, true);
ourRequest.setRequestHeader('X-MBX-APIKEY',keys['akey']);
ourRequest.onload = function(){
ourData = JSON.parse(ourRequest.responseText);
console.log(ourData);
}
ourRequest.send();
</script>
</html>
crypto-js.js文件:https://drive.google.com/file/d/1ZB5zTCpaz2M_01KcOZa1HLWDtAQOlKQ3/view?usp=sharing
最佳答案
转到项目文件夹并运行npm init -y
和npm i crypto-js --save
,然后执行以下步骤:
node filename.js
关于javascript - 当我运行 Node js时收到错误: SyntaxError: Unexpected token '<' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64106871/