2017-04-24 90 views
0

我使用httr來查詢Open Targets API如何使用httr請求API令牌?

我收到了我的API憑證(APP_NAME和密碼),現在我想通過嘗試對Python的翻譯提供指導索取令牌:

import requests 
API='https://www.targetvalidation.org/api/latest/' 

jwt = requests.get(API + 'public/auth/request_token', 
        params={'app_name':<appname>,'secret':<secret>}) 

print(jwt.json()) 

這就是我試圖用R和HTTR:

library(httr) 
app_name <- "myappname" 
secret <- "mysecret" 
token <- 
GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", app_name = app_name, secret = secret) 
token <- GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", add_headers(app_name = app_name, secret = secret)) 
token <- GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", config = list(app_name = app_name, secret = secret)) 

# In all cases, this is what I get 
token 
# Response [https://www.targetvalidation.org/api/latest/public/auth/request_token] 
# Date: 2017-04-24 08:24 
# Status: 400 
# Content-Type: application/json 
# Size: 60 B 
# {"message": {"app_name": "app name [appname] is required"}} 

什麼是正確的語法httr要求該令牌?

謝謝!

回答

2

你要傳遞的參數爲query,如httr quickstart解釋說:

token <- 
GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", 
query=list(app_name = app_name, secret = secret) 
) 
相關問題