Twitter Authentication with R - r

I am following the latest update on [twitteR homepage][1], and I can't pass the authorization process. I am using Windows 8.1 and the most up to date R packages and R studio/R.
I tried disabling my firewall-- that didn't work.
I tried adding the base64enc package (some people claim that it helped them) but it didn't work.
I need to get this right because it's my first year project for my PhD in Psychology and my adviser will really not be pleased if I can't get this to work.
library("base64enc")
library("twitteR")
library("ROAuth")
api_key <- "XXXXXXXXXXXXXXXXX"
api_secret <- "XXXXXXXXXXXXXXXXX"
access_token <- "XXXXXXXXXXXXXXXXX"
access_secret <- "XXXXXXXXXXXXXXXXX"
setup_twitter_oauth(api_key, api_secret, access_token, access_secret)
This is the output I am getting back:
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

I believe with the new release in Twitter API an OAuth handshake is necessary for every request you do.
I have extracted tweets recently and my code below using setup_twitter_oauth() works perfectly fine.
First you have to get your api_key and your api_secret as well as your access_token and access_token_secret from your app settings on Twitter. Just click on the “API key” tab to see them.
consumerKey <- "xyz" consumerSecret <- "xyz" accessToken <- "xyz"
accessTokenSecret <- "xyz"
setup_twitter_oauth(consumerKey, consumerSecret, accessToken,
accessTokenSecret)

I figured it out. I needed to use an old version of the httr package.
So on the author Github, some people were saying to use the 0.6.0 version but that's actually causing more problems. By trial and error, I figured out that it's the 1.0.0 version that is necessary. Here is the line of code.
devtools::install_version("httr", version="1.0.0", repos="http://cran.us.r-project.org")
P.S. I changed the keys. Those posted don't work anymore.

Related

twitteR API for R

I want to use Twitter API for R:
I'm using the following R Library-
library(twitteR)
I made my Twitter Developer Account and generate access_token, access_secret, consumer_secret, consumer_key.
consumer_key <- XXXXX
consumer_secret <- XXXXX
access_token <- XXXXX
access_secret <- XXXXX
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
Every time I'm facing the same error:
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
I read over stack exchange that I need to load the library base64enc. I tried doing that but still gave the same error.
Kindly suggest some movearounds.

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues

I am trying to use the TumblR package in R to set up the Oauth Authentication to Retrieve a user's dashboard using the second example in
tumblR documentation
However I get the following error, it seems that using twitter others have been able to use a different function to get around this, but I am not finding the same function available for Tumblr.
See twitter package for R authentication: error 401
My code
consumer_key <- OKey
consumer_secret <- SKey
appname <- App_name
tokenURL <- 'http://www.tumblr.com/oauth/request_token'
accessTokenURL <- 'http://www.tumblr.com/oauth/acces_token'
authorizeURL <- 'http://www.tumblr.com/oauth/authorize'
app <- oauth_app(appname , consumer_key, consumer_secret)
endpoint <- oauth_endpoint(tokenURL, authorizeURL, accessTokenURL)
token <- oauth1.0_token(endpoint, app)
The error I am receiving is the following.
Error in init_oauth1.0(self$endpoint, self$app, permission =
self$params$permission, : Unauthorized (HTTP 401)
I am using R version 3.4.0 and Rstudio Version 1.1.463
Reply from the package maintainer.
I'm sorry for the delay in the reply, I'm currently out for work.
The problem you reported depends on the change in the http protocol. The API URLs are now passed to https.
You can use
tokenURL <- 'https://www.tumblr.com/oauth/request_token'
accessTokenURL <- 'https://www.tumblr.com/oauth/acces_token'
authorizeURL <- 'https://www.tumblr.com/oauth/authorize'
I realized it only thanks to your report.
During the Christmas holidays, I plan to arrange the package.
If you have other evidence, let me know.

R TwitteR package authorization error

I am following the latest update on twitteR homepage, and I can't pass the authorization process.
library(devtools)
install_github("twitteR", username="geoffjentry")
library(twitteR)
api_key <- "XXXXXXXXXXXXXXXXX"
api_secret <- "XXXXXXXXXXXXXXXXX"
access_token <- "XXXXXXXXXXXXXXXXX"
access_secret <- "XXXXXXXXXXXXXXXXX"
setup_twitter_oauth(api_key, api_secret, access_token, access_secret)
This is the output I am getting back:
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
I have also tried setup_twitter_oauth(api_key, api_secret), and this is the error message:
[1] "Using browser based authentication"
Error in init_oauth1.0(endpoint, app, permission = params$permission) :
client error: (401) Unauthorized
I don't think there are any other options in setup_twitter_oauth. Does anyone else encounter this error?
set callback url to http://127.0.0.1:1410 in app settings in twitter
This error happens when your app is missing the callback url. To solve this issue go to https://apps.twitter.com/ select your application and then go to SETTINGS scroll down to CALLBACK URL and enter ( http://127.0.0.1:1410 ). This should allow you to run browser verification.
Or you can enter the access_token and access_secret in R to trigger local verification.
consumer_key <- " YOUR CONSUMER KEY "
consumer_secret<- " YOUR CONSUMER SECRET "
access_token <- " YOUR ACCESS TOKEN "
access_secret <- " YOUR ACCESS SECRET "
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
I have tried setting call back URL to ( http://127.0.0.1:1410 ), updating all packages related to this package. Nothing solved my problem.
then i installed httk httpuv packages and did the lines below:
consumer_key <- " YOUR CONSUMER KEY "
consumer_secret<- " YOUR CONSUMER SECRET"
setup_twitter_oauth(consumer_key, consumer_secret,
access_token=NULL, access_secret=NULL)
It worked like a beauty.
Doing the above takes to a web page and you manually authorize the app.
While this may not be the solution to the question, it is definitely a workaround to the authentication roadblock.
try install.packages('base64enc') . it worked for me. found it in github discussion.
I had the same problem. Tried all the suggestions I found on the net but in vain.
Probably it has to do with the Callback URL, I had skipped it earlier.
Created a new app, this time included it - http://127.0.0.1:1410 and it worked for me.
Here is the code I used:
library(httr)
library(devtools)
library(twitteR)
library(base64enc)
consumer_key <- 'XXXXXXXXXXXX'
consumer_secret <- 'XXXXXXXXXXXX'
access_token <- 'XXXXXXXXXXXX'
access_secret <- 'XXXXXXXXXXXX'
setup_twitter_oauth(consumer_key , consumer_secret, access_token, access_secret)
tw <- searchTwitter("LFC",n=100,lang="en")
Hope it helps.
I faced the same problem and tried all latest httr download and libraries but still the problem was there. Then I created a new APP in twitter and used API keys and other credentials in the code and now the problem solved.
I was using an APP which i created 8 months back ....regenerating the API credentials may also solve for the existing APP.
Try using this
setup_twitter_oauth(apiKey, apiSecret, access_token = accessToken, access_secret = accessSecret)
I got it fixed by manually generating access token at apps.twitter.com site and pass that as argument to the api which will force to use local authentication rather than browser authentication.
I encountered the same error:
"Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'"
and after trying the different solutions posted here in the stackoverflow, I still did not get the problem solved. I have regenerated my consumer key and consumer secret and supplied it to the following lines in my R script:
consumer_key <- 'XXconsumer_keyXX'
consumer_secret <- 'XXconsumer_secretXX'
access_token <- 'XXaccess_tokenXX'
access_secret <- 'XXaccess_secretXX'
setup_twitter_oauth(consumer_key , consumer_secret, access_token, access_secret)
What I did to get it right and get the OAuth authentication handshake is to supply the twitter supplied consumer key, consumer secret, access token, access secret value directly to the 5th line above, that is,
setup_twitter_oauth("xxconsumer_key_xx", "xxconsumer_secretxx", "xxaccess_tokenxx", "xxaccess_secretxx")
This works for me and hope it will for you.
I also had this issue and went through everything posted here to no avail. I finally looked at Windows Firewall and realized I had not made an exception for Rstudio. Everything works now!

twitteR ROAuth handshake error: not generating the PIN option

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.
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!
twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
This worked for me.

Invalid Request token using OAuth and R - Is the R-code correct?

I'm revising my original query to ask specifically if anyone can see a reason that the R-code I give below would, in of itself, lead to an invalid request token. If not, I'll know my issue lies elsewhere.
I’m trying to use the twitteR package as I’ve gotten to the Twitter chapter in Jeffrey Stanton’s free e-book on Data science which is helping me learn R. I get so far and then Twitter gives me this message:
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’ve got the bitops, RCurl, RJSONIO, twitter and ROAuth packages installed. I then run this code(NB I can't post links because my reputation is too low):
reqURL <- "//api.twitter.com/oauth/request_token"
accessURL <- "//api.twitter.com/oauth/access_token"
authURL <- "//api.twitter.com/oauth/authorize"
consumerKey <- "abc"
consumerSecret <- "xyz"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
Followed by this:
twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") )
I then get this prompt:
To enable the connection, please direct your web browser to:
http://api.twitter.com/oauth/authorize?oauth_token=Kxa...
When complete, record the PIN given to you and provide it here:
At this point I can’t seem to copy the twitter link, so I hand type it(!) into my browser and I get the message from Twitter I started my question with.
I’ve tried a number of times with the same outcome. The OAuth bit in the TwitteR vignette on r-project doesn’t have anything on this (it assumes I’d have done it right I suppose!) and the example on page nine of the TwitteR package description doesn’t help me either.
Thanks.
I’ve kind of answered my original query myself. I quit the R-studio project I was working in, recreated my access token and access token secret from within the twitter developer site, and then applied this code in a new R-studio project:
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)
download.file(url="http://curl.haxx.se/ca/cacert.pem",
destfile="cacert.pem")
twitCred$handshake(cainfo="cacert.pem")
I got that from here: TwitteR, ROAuth and Windows: register OK, but certificate verify failed
This combination of things stopped me getting the message from twitter that the request token was invalid. So I then get the link to twitter which now works:
To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=xxxx
However I didn’t get much further, so I’ve written a new question here: Where does twitteR PIN code appear during R oauth authentication?
I faced the same issue . I managed in two ways:
(1) Use R console instead of R studio
OR
(2) You take snapshot of the link and convert into text using OCR software(this)
Thanks and regards!!!

Categories

Resources