4

I am currently trying to send tweets from R, but I cannot get around the following error:

Error in .self$twFromJSON(out) : 
  Error: Could not authenticate with OAuth.

I have followed the directions in the twitteR vignette and the other stackoverflow questions concerning the matter (http://stackoverflow.com/questions/8122879/roauth-on-windows-using-r), but none seem to get around this error. Here is the code I am using:

library("twitteR")
library('ROAuth')

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

Through here works. registerTwitterOAuth returns TRUE, so you would think that everything worked. But when I try and send a tweet, I get the error listed above.

I'm trying to send a tweet by doing:

tweet("text to tweet")

This results in:

Error in .self$twFromJSON(out) : 
  Error: Could not authenticate with OAuth.

Not sure what's going wrong. The OAuth validation seems to work, but then I am unable to send tweets.

Josh W.
  • 1,123
  • 1
  • 10
  • 17

2 Answers2

3

This hopefully was resolved with the version that I just uploaded yesterday. If you're not already using 0.9.1 version of ROAuth, can you update your package and try again?

geoffjentry
  • 4,674
  • 3
  • 31
  • 37
  • 1
    I'm actually on Windows, and it looks like the latest version of the windows binary is 0.9.0. – Josh W. Feb 21 '12 at 17:55
  • 1
    Give it a few days, it takes a while for the Win & Mac versions to catch up on CRAN - different people manage those repositories. – geoffjentry Feb 21 '12 at 18:27
  • Thanks, I'll check in a few days to see if it's been updated. – Josh W. Feb 21 '12 at 19:07
  • I have updated the package to 0.9.1, and I get the same error. – Josh W. Feb 22 '12 at 18:11
  • Are you sure that those are the versions that are loaded in when you try? For instance this didn't work for me 2 days ago: library(twitteR); load("credTwit.rda"); registerTwitterOAuth(cred); tweet("text to tweet") and now it does. Can you double check w/ a sessionInfo() – geoffjentry Feb 22 '12 at 18:38
  • 1
    Turns out that my twitteR package was not up to date. After updating to the latest version, I now receive an error after this step: Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")) which results in this error: Invalid response from site, please check your consumerKey and consumerSecret and try again. I am absolutely sure there that the consumerkey and secret are correct, so not sure what's going on. Cred$handshake() also does not work. – Josh W. Feb 22 '12 at 22:23
  • 1
    My WAG would be that it has to do w/ the cainfo. It's possible that I somehow broke that, although I don't see what could have done that (of course, if I had that ability, I'd never have a bug). At this point it might be better to email me and we can hash it out in long form instead of via SO comments - the problem in the original post was definitely corrected by 0.9.1, this seems like something else. – geoffjentry Feb 22 '12 at 23:15
2

I just updated twitteR and ROAuth packages and ran these commands, and everything worked for me:

cred = getTwitterOAuth(consumerKey, consumerSecret)
registerTwitterOAuth(cred)
tweet("something incredibly interesting...")

Seems that twitterR now provides a cleaner interface to register the OAuth credential, which does not require explicit use of the OAuthFactory$new or handshake calls. When I tried explicitly calling these functions, things started to break. But when I used the interface above, everything worked smoothly.

Clayton Stanley
  • 7,513
  • 9
  • 32
  • 46
  • Tried the code suggested. Received the following error after executing the "registerTwitterOauth" command: Error in substring(digest, (1:hashlength) * 2 - 1, (1:hashlength) * 2) : cannot open file 'C:/R/R-2.15.2/library/digest/R/digest.rdb': No such file or directory – user2433346 May 30 '13 at 16:54
  • @user2433346 Not sure on that; my test was with OS X 10.6.8 with R 3.0 – Clayton Stanley May 30 '13 at 17:55