2017-08-27 1 views
1

POSTメソッドを使用してAPIに認証しようとしています。ここに私がKite Connect APIを参照しているドキュメントがあります。 私はどこが間違っているのか理解できません。間違いはチェックサムまたはPOSTですか?レスポンスキーとチェックサム付きのREST APIを使用したPOST認証

library(digest) 
require("httr") 

my_api <- "xxx" 
my_req_token <- 'yyy' 
my_secret <- 'zzz' 

check<-hmac(my_req_token,paste0(paste0(my_api,my_req_token),my_secret),algo=c('sha256')) 

url <- 'https://api.kite.trade/session/token' 
login <- list(api_key=my_api, 
       request_token = my_req_token, 
       checksum = check) 

response<- POST(url,body= login) 

これは私が受け取った応答です。

> response 
Response [https://api.kite.trade/session/token] 
Date: 2017-08-27 12:34 
Status: 400 
Content-Type: application/json 
Size: 81 B 

> content(response, "parsed", "application/json") 
$status 
[1] "error" 

$message 
[1] "Missing api_key" 

$error_type 
[1] "InputException" 

答えて

0

問題が解決され、これを与えます。ポストデータは、 'アプリケーション/ x-www-form-urlencodedで' を形成するエンコード引数を設定することなく、この

library(digest) 
require("httr") 

my_api <- "xxx" 
my_req_token <- 'yyy' 
my_secret <- 'zzz' 

#use digest insted of hmac; digest serializes argument first, use serialize arg to disable that 
check<-digest(paste0(my_api, my_req_token, my_secret), algo='sha256', serialize=FALSE) 

url <- 'https://api.kite.trade/session/token' 
login <- list(api_key=my_api, 
       request_token = my_req_token, 
       checksum = check) 

#post data should be sent as 'application/x-www-form-urlencoded', setting encode arg to form does this 
response<- POST(url,body= login, encode='form') 

parsed_content <- content(response, "parsed", "application/json") 
0

ショット

#devtools::install_github("hrbrmstr/curlconverter") 

library(curlconverter) 

curlExample <- 'curl https://api.kite.trade/session/token 
    -d "api_key=xxx" 
    -d "request_token=yyy" 
    -d "checksum=zzz"' 

resp <- make_req(straighten(curlExample)) 
resp 
+0

'> RESP [[1]] 関数() HTTR :: VERB(として送信されるべきです動詞= "GET"、url = "https://api.kite.trade/session/token") ' –

+0

これはコードから得た応答です。 *チェックサムにhmacが追加されました。 –

関連する問題