twitteR and ROAuth

2019-04-10 05:44发布

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.

2条回答
三岁会撩人
2楼-- · 2019-04-10 05:59

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-10 06:06

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?

查看更多
登录 后发表回答