Coinbase Sandbox API 未经授权的 API 密钥
我已经为 coinbase 沙箱生成了许多 API 密钥,并尝试使用它们来获取用户帐户列表。但是我不断收到相同的错误 401 未经授权的 API 密钥。
我已经阅读了文档,并且非常确定我做的一切都是正确的。
下面是我的代码。如果有人能看到出了什么问题,我们将不胜感激。
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
// request url
String url = "https://api.coinbase.com/v2/accounts";
long unixTime = Instant.now(clock).getEpochSecond();
String sha256hex = Hashing.sha256()
.hashString("rv3fSnIVN5R0DzINY6RRAronuWLAxPLV48XnGOFP+WL8Lh22bOJ0BvwyGH37hZ2tLRuTsjSnGCmK/dDM9FKNcw==", StandardCharsets.UTF_8)
.toString();
// create headers
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.set("CB-ACCESS-KEY", "63d1342304ba4d7fcc1297bf26a90418");
headers.set("CB-ACCESS-SIGN", sha256hex);
headers.set("CB-ACCESS-TIMESTAMP",""+unixTime);
headers.set("CB-ACCESS-PASSPHRASE","xdeqz62oak");
// build the request
HttpEntity request = new HttpEntity(headers);
ResponseEntity<LiveData> liveData = restTemplate.exchange(
url,
HttpMethod.GET,
request,
LiveData.class);
log.info(liveData.toString());
};
I have generated a number of API keys for coinbase sandbox and am trying to use them to get the list of user accounts. However I keep getting the same error 401 Unauthorised API key.
I have read through the documentation and am quite sure im doing everything right.
Below is my code. If anyone can see whats wrong it would be greatly appreciated.
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
// request url
String url = "https://api.coinbase.com/v2/accounts";
long unixTime = Instant.now(clock).getEpochSecond();
String sha256hex = Hashing.sha256()
.hashString("rv3fSnIVN5R0DzINY6RRAronuWLAxPLV48XnGOFP+WL8Lh22bOJ0BvwyGH37hZ2tLRuTsjSnGCmK/dDM9FKNcw==", StandardCharsets.UTF_8)
.toString();
// create headers
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.set("CB-ACCESS-KEY", "63d1342304ba4d7fcc1297bf26a90418");
headers.set("CB-ACCESS-SIGN", sha256hex);
headers.set("CB-ACCESS-TIMESTAMP",""+unixTime);
headers.set("CB-ACCESS-PASSPHRASE","xdeqz62oak");
// build the request
HttpEntity request = new HttpEntity(headers);
ResponseEntity<LiveData> liveData = restTemplate.exchange(
url,
HttpMethod.GET,
request,
LiveData.class);
log.info(liveData.toString());
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论