TwitteR, ROAuth and Windows: register OK, but certificate verify failed

I had received the error you described above in the past, but this has worked for me.

#=======================================================================================
## ON windows, we need to dowload the certificate for OAUTH
## NOTE:  you will need to setup an app on Twitter
## dev.twitter.com <- get your KEY/SECRET
#=======================================================================================


##########################################################################
## Load packages
##########################################################################

library(twitteR)
library(ROAuth)

## set the directory
setwd("~/your/directory/here")


## Windows users need to get this file
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")



##########################################################################
## Authenticate with Twitter
##########################################################################

## authenticate with the API
## requires that you have registered an app
KEY <- "KEY"
SECRET <-"SECRET"


## create an object that will save the authenticated onbject -- we can for later sessions
## will need to navigate to website and type in data to generate the file
## NOTE:  Only need to do this part once!!!
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(cainfo="cacert.pem")


## load the cred object in later sessions and simply pass to the registerTwitterOAuth
## After this file is saved, you only need to load the cred object back into memory
save(cred, file="twitter authentication.Rdata")


## Authenticate with Twitter = this is an important peice of code
registerTwitterOAuth(cred)


##########################################################################
## lets test out what our session limits look like
##########################################################################
rate.limit <- getCurRateLimitInfo()

## If return 350, Authenticated session = more API calls allowed / hour
rate.limit$hourlyLimit
rate.limit$remainingHits
rate.limit$resetTime

Leave a Comment