Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL certificate failed for twitteR in R

I know similar questions have been asked again. However, I've tried everything I found here and on google and nothing seems to work for me.

My code is the following:

reqURL <- "http://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- "xxxxxxxxxxx"
consumerSecret <- "xxxxxxxxxxxxxxxxxxx"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                         consumerSecret=consumerSecret,
                         requestURL=reqURL,
                         accessURL=accessURL,
                         authURL=authURL)
twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
registerTwitterOAuth(twitCred)

Here I get: [1] TRUE

But if I try this: tweets = searchTwitter('blabla', n=1500)

I get the following error: [1] "SSL certificate problem, verify that the CA cert is OK. Details:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) : Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Here are the packages and versions on my PC:

sessionInfo() R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Greek_Greece.1253  LC_CTYPE=Greek_Greece.1253   
[3] LC_MONETARY=Greek_Greece.1253 LC_NUMERIC=C                 
[5] LC_TIME=Greek_Greece.1253    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ROAuth_0.9.2   digest_0.6.2   twitteR_1.1.0  rjson_0.2.12  
[5] RCurl_1.95-4.1 bitops_1.0-5  

loaded via a namespace (and not attached):
[1] tools_2.15.1

Any help would be really useful!!

like image 335
Stergios Avatar asked Mar 11 '13 19:03

Stergios


2 Answers

Do the following first, and then run your code:

library(RCurl) 

# Set SSL certs globally
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

This usually corrects the issue you were experiencing.

EDIT (Aug 2014): Or better yet, try to use the httr package instead (which is a friendly wrapper of RCurl with useful default options set for you)

like image 136
Tony Breyal Avatar answered Oct 13 '22 00:10

Tony Breyal


finally i got the solution, please try this method. this is very easy

library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)

api_key = "aaa"
api_secret = "bbb"
access_token = "ccc"
access_token_secret = "ddd"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
like image 25
Selcuk Akbas Avatar answered Oct 13 '22 01:10

Selcuk Akbas