Pergunta

This question actually answers all questions related to twitteR ROAuth problems:

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

TwitteR and ROAuth both worked perfectly in my pc before. But the code chunk is not generating the PIN option anymore. It pops out the following:

twitCred$handshake(cainfo="cacert.pem")
Error: Unauthorized

Previously twitCred$handshake(cainfo="cacert.pem") directs to:

To enable the connection, please direct your web browser to: 
https://api.twitter.com/oauth/authorize?oauth_token=SevxcpCh9riO5PPrI8U8____
When complete, record the PIN given to you

I tried my code in spark rstudio server. Then the code works perfectly (generating the option to enter the PIN, which is currently not generated in my pc). The code is:

require(twitteR)
require(ROAuth)

requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "______________"
consumerSecret <- "___________________"


twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret, requestURL=requestURL, accessURL=accessURL,
authURL=authURL)


setwd("/home/__")
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
twitCred$handshake(cainfo="cacert.pem")
  To enable the connection, please direct your web browser to: 
  https://api.twitter.com/oauth/authorize?oauth_token=SevxcpCh9riO5PPrI8U8____
  When complete, record the PIN given to you

Any help is appreciated.

Foi útil?

Solução 2

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

This worked for me.

Outras dicas

It is necessary for the Twitter App to have read, write permissions. This is was what made me bypass the authorization errors. Please note the following instructions:

Create a Twitter application at http://dev.twitter.com. Make sure to give the app read, write and direct message authority. Take note of the following values from the Twitter app page: "API key", "API secret", "Access token", and "Access token secret".

install.packages(c("devtools", "rjson", "bit64", "httr")) Make sure to restart your R session at this point

library(devtools) install_github("twitteR", username="geoffjentry") library(twitteR) setup_twitter_oauth("API key", "API secret")

The API key and API secret are from the Twitter app page above. This will lead you through httr's OAuth authentication process. I recommend you look at the man page for Token in httr for an explanation of how it handles caching.

You should be ready to go!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top