RCurl, basic authentication with API key

醉酒当歌 提交于 2019-12-03 22:36:22

问题


I used to use RCurl, to grab the data that needs login. Now I have to grab the data using api key (as well as userid,password) and it needs a basic authentication (Radian6 api : http://socialcloud.radian6.com/docs/read/Getting_Started)

If it doesn't need an authentication, the code will be something like..

getURL("https:// address", userpwd="id:pswd", httpauth = 1L)

but I have no idea how to plug in api key for authentication. So far I was able to find examples written in python or Java but haven't found R example yet. Can anyone point me to the right direction? I'm wondering how I can use RCurl for basic authentication and how I can use a token to grab the data. (fyi, this is how python works :Urllib2 authentication with API key)

Any advice will be very appreciated!


回答1:


You might find it a little easier to use httr. The code would look something like this:

library(httr)

req <- GET("https://address.com/authenticate", 
  authenticate("user", "pass", type = "basic"),
  add_headers(auth_appkey = api_key))
stop_for_status(req)
content(req)
# Then extract token etc


来源:https://stackoverflow.com/questions/23286900/rcurl-basic-authentication-with-api-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!