首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coinbase API -无法发布

Coinbase API -无法发布
EN

Stack Overflow用户
提问于 2021-10-26 08:05:02
回答 1查看 223关注 0票数 1

这有什么问题吗?为什么我不能发布购买?我一直收到401未授权的电话。接口拥有正确的权限(wallet:buys:create)

我应该指出,我的工作,我可以从帐户读取所有信息。

代码语言:javascript
复制
$time = 'https://api.coinbase.com/v2/time'
$epochtime = [string]((Invoke-WebRequest $time | ConvertFrom-Json).data).epoch

$method = 'POST'
$requestpath = '/v2/accounts/xxxxxxxx-3ecb-xxxxxxxx-xxxxxxxx/buys'
$endpoint = "https://api.coinbase.com/$($requestpath)"
$secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

$sign = $epochtime + $method + $requestpath
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::UTF8.GetBytes($secret_key)
$computeSha = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($sign))

$signature = ([System.BitConverter]::ToString($computeSha) -replace "-").ToLower()

$header = @{
"CB-ACCESS-SIGN"=$signature
"CB-ACCESS-TIMESTAMP"=$epochtime
"CB-ACCESS-KEY"='xxxxxxxxxxxxxxxxxxxx'
}

$body = '{"amount": "10", "currency": "XLM", "payment_method": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "commit": "true", "quote":"false"}'
function Get-CoinBase($method, $endpoint, $header, $body)
{
  $result = Invoke-WebRequest $endpoint -Headers $header -Method $method -body $body -ContentType "application/json" -UseBasicParsing
  write-host $APImethod -f yellow

  return $result
}

$AccountBAL = Get-CoinBase -method "POST" -endpoint $endpoint -header $header -body $body
EN

回答 1

Stack Overflow用户

发布于 2021-10-28 18:41:46

我之前错过了,你没有在你的哈希中包括身体。当您签名时,您需要包括正文选项。

代码语言:javascript
复制
$sign = $epochtime + $method + $requestpath

应该是

代码语言:javascript
复制
$sign = $epochtime + $method + $requestpath + $body

下面是他们的例子

代码语言:javascript
复制
var message = timestamp + req.method + req.path + req.body;
//create a hexedecimal encoded SHA256 signature of the message
var signature = crypto.createHmac("sha256", apiSecret).update(message).digest("hex");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69719536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档