Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROauth on Windows using R

Tags:

r

oauth

twitter

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).

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?

Here is the error:

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

EDIT: 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()
like image 299
Btibert3 Avatar asked Nov 14 '11 14:11

Btibert3


1 Answers

UPDATE MAY 2013

Seeing as I keep seeing people mention these issues on Windows, if you do the following before running your R script, it should solve the issue automatically without you needing to do anything else in this post:

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

This will set the option gloabally and will be used in all RCurl calls.

I'll leave the rest of the post below for reference.


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

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

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.

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")

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.

Hope that helps a little.

Tony Breyal

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)

UPDATE 2011:

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"))
like image 87
Tony Breyal Avatar answered Nov 05 '22 14:11

Tony Breyal