使用 R 在 Windows 上进行 ROauth [英] ROauth on Windows using R

查看:52
本文介绍了使用 R 在 Windows 上进行 ROauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了 SO 并看到有关该主题的一些问题,但我没有找到任何与 Windows 直接相关的内容(我之前的帖子是针对 Linux 的).

I searched SO and saw a few questions posted on the topic, but I didn't find anything directly related to Windows(my previous post was for Linux).

更具体地说,我想使用 twitteR 包,但我无法让身份验证工作.到目前为止,我可以访问其他机器,但是这一次,我需要完全留在 Windows 中.我该如何解决这个问题?

More specifically, I am tying to use the twitteR package, but I can not get Authentication to work. Up until now, I have had access to other machines, but this time, I need to stay entirely within Windows. How can I get around this?

这里是错误:

Error in curlPerform(curl = curl, URL = url, postfields = fields, writefunction = reader$update,  : 
  SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

生成那个的代码......来自 twitteR 包的文档

And the code that generates that....from the documentation of the twitteR package

cred <- OAuthFactory$new(consumerKey = KEY, 
    consumerSecret = SECRET,
    requestURL = "https://api.twitter.com/oauth/request_token", 
    accessURL = "https://api.twitter.com/oauth/access_token", 
    authURL = "https://api.twitter.com/oauth/authorize")
cred$handshake()

推荐答案

2013 年 5 月更新

看到我一直看到人们在 Windows 上提到这些问题,如果您在运行 R 脚本之前执行以下操作,它应该会自动解决问题,而您无需在本文中执行任何其他操作:

library(RCurl) 
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

这将全局设置选项,并将在所有 RCurl 调用中使用.

我将在下面留下帖子的其余部分以供参考.

注意:这不是一个直接的解决方案,但对于评论或#rstats 推文来说也太长了...

NOTE: This isn't a direct solution, but it's also too long for a comment or an #rstats tweet...

阅读输出,问题似乎出在 cURL(以及包 RCurl)上.我可以使用 RCurl_1.6-10 为我在 Windows 7 x64 Pro 和 R2.14.0 上发生的不同应用程序重新创建相同的错误:

Reading the output, the problem seems to be with cURL (and hence package RCurl). I can recreate the same error for a different application which happens to me on Windows 7 x64 Pro with R2.14.0 using RCurl_1.6-10:

library(RCurl)
u <- "https://raw.github.com/tonybreyal/Blog-Reference-Functions/master/R/bingSearchXScraper/bingSearchXScraper."
x <- getURL(u)
#Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 
#  SSL certificate problem, verify that the CA cert is OK. Details:
#error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

错误代码是一样的.在您的情况下,这意味着 Twitter 正在向您发送证书,告诉您它们是真正的 Twitter 网站.但是你怎么知道他们说的是实话呢?在您系统的某个地方,您需要有一个可以确认它的文件,从可信来源获得.

The error code is the same. In your case it means that Twitter is sending you a certificate to tell you that they are the real Twitter website. But how do you know that they are telling the truth? Somewhere on your system you need to have a file which can confirm it, obtained from a trusted source.

一种解决方案是按如下方式获取该文件以解决问题(注意,还有其他网站提供此类文件,我使用了官方 cURL 网站):

One solution is to get that file as follows which solves the issue (note, there are other websites which provide such files, I've used the official cURL website):

download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
x <- getURL(u, cainfo = "cacert.pem")

我没有看过 ROAuth 的内部结构(用 S3/S4/Reference-classes 编写的任何东西都吓坏了我)但在某些时候它需要设置 cainfo 参数来克服这个问题(在 Windows 上)也就是说 - 对于我上面的例子,似乎在 Ubuntu 上工作正常).我不知道 ROAuth 是否允许用户以某种方式添加这些 curl 参数,但这将是解决问题的方法.

I've not looked at the internals of ROAuth (anything written in S3/S4/Reference-classes scares the hell out of me) but at some point it would need to set the cainfo parameter to overcome this issue (on Windows that is - seems to work fine on Ubuntu for my example above). I don't know if ROAuth lets the user add these curl parameters somehow but that would be the way to go to solve it.

希望能有所帮助.

托尼·布雷亚尔

附言另一种方法是可能的,并避免从 cURL 下载证书,但不推荐用于您正在做的事情类型(说真的,为了您使用 twitter 的目的,我建议您不要这样做):

P.S. another method is possible, and avoids downloading the certificate from cURL, but is not recommended for the type of thing you're doing (seriously, for your purpose of using twitter, I would recommend against this big time):

x <- getURL(u, ssl.verifypeer = FALSE)

2011 年更新:

这似乎可以跨平台工作(无论如何,Ubuntu 和 Windows)并且不需要您直接下载 SSL 证书,因为 RCurl 已经随附:

This seems to work across platforms (well, Ubuntu and Windows at any rate) and does not require you to directly download the SSL certs as RCurl comes with them already:

 x <- getURL(u, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))

这篇关于使用 R 在 Windows 上进行 ROauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆