0

我正在尝试访问coinbase api以在我的 ubuntu 终端上生成地址。

curl -k -X GET  "https://api.coinbase.com/v2/accounts/3e3835d3----/addresses"  -H "CB-VERSION: 2015-04-08"  -H  "accept: application/json;charset=utf-8" -H "Authorization: Bearer abd90df5f27a7b170cd775abf89d632b350b7c1c9d53e08b340cd9832ce52c2c"  

返回以下错误。

{"errors":[{"id":"invalid_token","message":"访问令牌无效"}]}

我不知道作为授权持有人要传递什么。我只有 API 密钥和 API 密钥。如果需要采取其他步骤或其他文件,请告诉我。如果您需要更多信息,请同时询问。

一个例子会很有帮助。提前致谢。

4

2 回答 2

1

请尝试理解此python文档。它说

> All REST requests must contain the following headers:
> 
>   CB-ACCESS-KEY API key as a string  
>   CB-ACCESS-SIGN Message signature (see below)  
>   CB-ACCESS-TIMESTAMP Timestamp for your request
> 
> All request bodies should have content type application/json and be
> valid JSON.
> 
> Example request:
> 
>     curl https://api.coinbase.com/v2/user \   
    --header "CB-ACCESS-KEY:<your api key>" \     
    --header "CB-ACCESS-SIGN: <the user generated message signature>" \     
    --header "CB-ACCESS-TIMESTAMP: <a timestamp for your request>"
>
> The CB-ACCESS-SIGN header is generated by creating a sha256 HMAC using
> the secret key on the prehash string timestamp + method + requestPath
> + body (where + represents string concatenation). The timestamp value is the same as the CB-ACCESS-TIMESTAMP header.
> 
> The body is the request body string. It is omitted if there is no
> request body (typically for GET requests).
> 
> The method should be UPPER CASE.
> 
> The requestPath is the full path and query parameters of the URL,
> e.g.: /v2/exchange-rates?currency=USD.
> 
> The CB-ACCESS-TIMESTAMP header MUST be number of seconds since Unix
> Epoch in UTC.
> 
> Your timestamp must be within 30 seconds of the API service time, or
> your request will be considered expired and rejected.

因此,我在 php 中为获取授权承载以发送 curl 请求所做的操作如下:

$sig = hash_hmac('sha256', $requeststring, $coinbaseclientsecret);
于 2018-03-22T08:07:00.717 回答
0

通过快速阅读 API 文档,您会发现您需要使用 OAuth 作为承载。有关示例代码,请参阅Coinbase 集成文档

于 2018-03-19T12:28:12.823 回答