No PIN during ROAuth process in R Studio

92 views Asked by At

I want to access twitter via R Studio [version 3.5.1 (2018-07-02)] to download Tweets matching a certain keyword.

I am using the packages "twitteR" and "ROAuth". My twitter account has "Read, write, and direct messages" set as access permission.

My problem is the exact same as stated here

The only difference is, that the there provided solution doesn't work for me.

By executing the code (see linked post) with my keys I am able to hit the "authenticate" button on the opening website, get immediately redirected to the callback URL and see no PIN.

Twitter demands a callback URL, so I can't delete it from my Twitter account settings.

I tired:

  • reinstalling the packages
  • changing the working directory
  • installed the packages "openssl" and "httpuv" as suggested
  • changed the twitter access permission of my account from "Read and write" to "Read, write, and direct messages"
  • used the setup_twitter_oauth function which produced the error message:
> setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

My main approach is based on the linked topic above. I use this code:

requestURL <-  "https://api.twitter.com/oauth/request_token"  
accessURL =    "https://api.twitter.com/oauth/access_token"  
authURL =      "https://api.twitter.com/oauth/authorize"  
consumerKey = 'YYY'
consumerSecret = 'XXX'
twitCred <- OAuthFactory$new(consumerKey='YYY',  
                             consumerSecret='XXX',  
                             requestURL=requestURL,  
                             accessURL=accessURL,  
                             authURL=authURL)

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

twitCred$handshake(cainfo= system.file("CurlSSL", "cacert.pem", package = "RCurl"))

A second approach was to use the following function, which produced the same error as stated above.

TwitterOAuth<-function()
{
  reqURL   <- "https://api.twitter.com/oauth/request_token"
  accessURL<- "https://api.twitter.com/oauth/access_token"
  authURL  <- "https://api.twitter.com/oauth/authorize"
  twitCred <- OAuthFactory$new(consumerKey='YYY',
                               consumerSecret='XXX',
                               requestURL=reqURL,
                               accessURL=accessURL,
                               authURL=authURL)

  options(RCurlOptions = list(cainfo = system.file("CurlSSL", 
                                                   "cacert.pem", 
                                                   package = "RCurl")))

  twitCred$handshake()

  registerTwitterOAuth(twitCred)
}

TwitterOAuth()

This second approach generates a Twitter API link in R's console, when I click it immediately, I get directed to a Twitter page which states: "Whoa there! The request token for this page is invalid. It may have already been used, or expired because it is too old. Please go back to the site or application that sent you here and try again; it was probably just a mistake."

I expect to establish the connection between R and Twitter. I am not depending on the ROAuth package, if there is another package/way which allows me to download keyword related Tweets for a large time series, I would appreciate it.

Thank you very much for your help :).

1

There are 1 answers

0
StableSong On

Solution:

This time I did not require the package "ROAuth" but "httr" and "openssl" and I was able to use the function "setup_twitter_oauth" with my log-in data and it worked without any problems!

Btw: it didn't show me a PIN but the data can be directly downloaded into R!

According to this youtube video, the twitter account needs the "Read, write, and direct messages" permission.