R httr GET请求400错误GDAX [英] R httr GET request 400 error GDAX
问题描述
我正尝试使用 R
命中 GDAX ,并获得以下问题。如何使用 httr
解决问题。
响应[https ://api-public.sandbox.gdax.com/accounts]
日期:2017-12-07 20:30
状态:400
Content-Type:application / json; charset = utf-8
大小:53 B
以下是我的代码。请注意,这个问题只存在于 httr
包而不是
$ b $
library(digest)
library(httr)
library(RCurl)#for base64Decode
url< - https://api-public.sandbox.gdax.com/accounts
秘密&#;#来自GDAX沙箱的API秘密
api.key< - #API密钥来自GDAX沙箱
密码短语< - #来自GDAX沙箱的API密码短语
时间戳< - 格式(as.numeric(Sys.time()),digits = 13)#创建nonce
key< - base64Decode(secret,mode =raw)#encode api secret
what < - paste0(timestamp,GET,req.url)
sign< - base64Encode( hmac(key,what,algo =sha256,raw = TRUE))
连接器< - list(url = url,nonce = timestamp,signature = sign))
GET(url = connector $ url,
add_headers(
'CB-ACCESS-KEY'= api.key,
'CB-ACCESS-SIGN'=连接器$签名,
'CB-ACCESS-TIMESTAMP'=连接器$ nonce,
'CB-ACCESS-PASSPHRASE'=密码,
'Content-Type'='application / json'
)
)
但是,如果我使用 RCurl
,那么我可以使用以下代码获得响应内容。 $ b $ pre $ httpheader < - list('CB-ACCESS-KEY'= api.key,
'CB-内容类型'='应用程序/ json'=签名,
'CB-ACCESS-TIMESTAMP'=时间戳,
'CB-ACCESS-PASSPHRASE'=密码,
' )
connector< - list(url = url,header = httpheader)
getURLContent(url = connector $ url,
curl = getCurlHandle(useragent = R),
httpheader = connector $ header)
除非沙箱被恢复(我没有资料可以这样说),但是它在2017年年初退役,通讯方式很少,而且据我所知,仍然是这个日期。我将它记录在 gdax-java 库中。
I am trying to hit GDAX using R
and getting the following issue. How do I solve for the issue using httr
.
Response [https://api-public.sandbox.gdax.com/accounts]
Date: 2017-12-07 20:30
Status: 400
Content-Type: application/json; charset=utf-8
Size: 53 B
Below is my code. Please note that the issue exists only with httr
package and not with RCurl
(code provided in appendix)
library(digest)
library(httr)
library(RCurl) # for base64Decode
url <- "https://api-public.sandbox.gdax.com/accounts"
secret <- # API secret from GDAX sandbox
api.key <- # API key from GDAX sandbox
passphrase <- # API passphrase from GDAX sandbox
timestamp <- format(as.numeric(Sys.time()), digits=13) # create nonce
key <- base64Decode(secret, mode="raw") # encode api secret
what <- paste0(timestamp, "GET", req.url)
sign <- base64Encode(hmac(key, what, algo="sha256", raw=TRUE))
connector <- list(url = url, nonce = timestamp, signature = sign))
GET(url=connector$url,
add_headers(
'CB-ACCESS-KEY'=api.key,
'CB-ACCESS-SIGN'=connector$signature,
'CB-ACCESS-TIMESTAMP'=connector$nonce,
'CB-ACCESS-PASSPHRASE'=passphrase,
'Content-Type'='application/json'
)
)
If however, I use RCurl
then I am able to get a response content using the following code.
httpheader <- list('CB-ACCESS-KEY'=api.key,
'CB-ACCESS-SIGN'=sign,
'CB-ACCESS-TIMESTAMP'=timestamp,
'CB-ACCESS-PASSPHRASE'=passphrase,
'Content-Type'='application/json')
connector <- list(url = url, header = httpheader)
getURLContent(url = connector$url,
curl=getCurlHandle(useragent="R"),
httpheader=connector$header)
unless the sandbox was reinstated (I have no info to say it was) it was decommissioned early 2017 with very little in the way of communication and is still down to this date as far as I'm aware. I documented this on the gdax-java lib.
这篇关于R httr GET请求400错误GDAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!