Authentication 继续获取Coinbase API调用的时间戳错误
我正在尝试使用apps脚本将我的google工作表连接到Coinbase API。当我尝试使用我的密钥进行身份验证时,我不断得到相同的错误{“errors”:[{“id”:“authentication_error”,“message”:“invalid timestamp”}]}代码401 我尝试检查我的请求和Coinbase服务器之间的时间差(看看是否超过30秒),但没有。(1589465439(矿山)/15894654664(服务器)) 那么什么是错误的呢 我的代码:Authentication 继续获取Coinbase API调用的时间戳错误,authentication,timestamp,coinbase-api,Authentication,Timestamp,Coinbase Api,我正在尝试使用apps脚本将我的google工作表连接到Coinbase API。当我尝试使用我的密钥进行身份验证时,我不断得到相同的错误{“errors”:[{“id”:“authentication_error”,“message”:“invalid timestamp”}]}代码401 我尝试检查我的请求和Coinbase服务器之间的时间差(看看是否超过30秒),但没有。(1589465439(矿山)/15894654664(服务器)) 那么什么是错误的呢 我的代码: var times
var timestamp = Math.floor(Date.now() / 1000) + 15;
Logger.log(timestamp);
var req = {
method: 'GET',
path: '/v2/accounts',
body: ''
};
var message = timestamp + req.method + req.path + req.body;
var secret = Utilities.base64Decode(apiKey);
secret = Utilities.newBlob(secret).getDataAsString();
//create a hexedecimal encoded SHA256 signature of the message
var hmac = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, message, secret);
var signature = Utilities.base64Encode(hmac);
Logger.log(signature);
var signatureStr = '';
for (i = 0; i < signature.length; i++) {
var byte = signature[i];
if (byte < 0)
byte += 256;
var byteStr = byte.toString(16);
// Ensure we have 2 chars in our byte, pad with 0
if (byteStr.length == 1) byteStr = '0'+byteStr;
signatureStr += byteStr;
}
Logger.log(signatureStr);
var options = {
baseUrl: 'https://api.coinbase.com/',
url: req.path,
method: req.method,
headers: {
'CB-ACCESS-SIGN': signatureStr,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-KEY': apiKey
}
};
var response = UrlFetchApp.fetch("https://api.coinbase.com/v2/accounts", options);
var timestamp=Math.floor(Date.now()/1000)+15;
Logger.log(时间戳);
var req={
方法:“GET”,
路径:'/v2/accounts',
正文:“”
};
var消息=时间戳+req.method+req.path+req.body;
var secret=Utilities.base64Decode(apiKey);
secret=Utilities.newBlob(secret.getDataAsString();
//创建消息的十六进制编码SHA256签名
var hmac=Utilities.computeHmacSignature(Utilities.MacAlgorithm.hmac___256,消息,秘密);
var签名=实用程序.base64Encode(hmac);
Logger.log(签名);
var signatureStr='';
对于(i=0;i
谢谢这是一个老问题,但如果问题仍然没有解决,我会看到一些改变来解决这个问题。我遇到了一个类似的问题,不得不解决它
headers: {
'CB-ACCESS-SIGN': signatureStr,
'CB-ACCESS-TIMESTAMP': timestamp.toString(),
'CB-ACCESS-KEY': apiKey
}
let signature = Utilities.computeHmacSha256Signature(message, secret);