RCurl,具有API密钥的基本身份验证 [英] RCurl, basic authentication with API key
问题描述
我曾经使用RCurl来获取需要登录的数据.现在,我必须使用api密钥(以及用户ID,密码)来获取数据,并且它需要基本身份验证(Radian6 api: http://socialcloud.radian6.com/docs/read/Getting_Started )
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)
但是我不知道如何插入api密钥进行身份验证.到目前为止,我能够找到用python或Java编写的示例,但尚未找到R示例.谁能指出我正确的方向?我想知道如何使用RCurl进行基本身份验证,以及如何使用令牌来获取数据. (仅供参考,这就是python的工作方式:使用API密钥的Urlib2身份验证)
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)
任何建议将不胜感激!
推荐答案
您可能会发现使用httr会更容易一些.代码看起来像这样:
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
这篇关于RCurl,具有API密钥的基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!