2

I'm trying to authenticate with Twitter using R, but I can't get a PIN.

The code I have is as follows:

download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")

reqURL <- "http://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- "foo"
consumerSecret <- "bar"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                             consumerSecret=consumerSecret,
                             requestURL=reqURL,
                             accessURL=accessURL,
                             authURL=authURL
                             )
twitCred$handshake(cainfo="cacert.pem", ssl.verifypeer=FALSE)

However, when I get the authorisation URL back and type that in, I still don't get a PIN : I just have a button to authorise the app, and then I end up back at the return URL I've previously specified.

This seems a very similar situation to this question Where does twitteR PIN code appear during R oauth authentication? but the remedy there (to ensure the request, access and auth URLs are all http rather than https) doesn't work for me.

I'm running R 3.0.0 on Windows 7, ROAuth is 0.9.2, twitteR 1.1.0 - any of those indicate why this problem is occurring?

Community
  • 1
  • 1
JamesF
  • 449
  • 1
  • 3
  • 15
  • Maybe you need to update your cacert.pem file. Have a look [**here**](http://stackoverflow.com/a/15348927/1478381) and see if this helps. This question has been posted so many times, with the *exact* same code. When you overcome this problem, it would be helpful to answer it yourself with *exactly* what you did because at the moment this question is getting asked about once per day. – Simon O'Hanlon Apr 17 '13 at 10:36
  • Thanks Simon. I get "C:\Users\V-JFOR~1\AppData\Local\Temp\Rtmp4Y79aI/cacert.pem' had status 309" when I try to refresh cacert.pem as you suggest. I think that's because curl's not working properly on my machine; where should the up to date cacert.pem be? In the R working directory? – JamesF Apr 19 '13 at 07:47

1 Answers1

0

The url returned from Twitter after authorizing the app had a "oauth_verifier". I used this as the PIN in R. I was able to copy and paste it into R where it asked for the PIN. No text appeared in R until I hit enter. The PIN seemed to be accepted. I tried registerTwitterOAuth(cred) and the TRUE response was returned. However, I'm still having problems getting any info returned from a search:

download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem") options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
r_stats<- searchTwitter("#Rstats", n=100, cainfo="cacert.pem")

[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