[英]Is that a way to make authorisation with header in R like in python?
我嘗試將我的r腳本連接到API。 我看到我們可以在python中做到這一點,所以我嘗試在R中做同樣的事情,但似乎不起作用
我想這樣做
http_url="https://ui.adsabs.harvard.edu/search/q=author%3A%22Alexandre%20Gallenne%22%20title%3A%22A%20distance%20to%20the%20Large%20Magellanic%20Cloud%20that%20is%20precise%20to%20one%20per%20cent%22&sort=date%20desc%2C%20bibcode%20desc&p_=0"
r=requests.get(http_url,headers={'Authorization:' 'Bearer ' + 'token'})
但是在
我嘗試了此操作(對不起,我無法給您任何示例,因為我的令牌是私有的)
require("httr")
require("jsonlite")
res_reques<-GET(url = http_url,add_headers("Authorization",'Bearer',token))
text<-content(res_reques,"text")
res_reques
響應狀態為200(這似乎是正確的,但是我沒有任何數據,並且那不是正常的,因為我的搜索有結果(如果您將http_url錄制在瀏覽器中)
也許您沒有正確使用add_headers
? 無法測試,我建議
add_headers(Authorization=paste("Bearer", token))
還要注意, text
應包含結果,而不是res_reques
(代碼的最后一行)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.