httr authentication with twitteR [closed] - r

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I’ve just updated to the current github version of twitteR and am having some difficulties with httr authentication. I start by running the following:
library(twitteR)
consumer_key <- "---------------------"
consumer_secret <- "------------------------------------------"
access_token <- "-------------------------------------------------"
access_secret <- "-------------------------------------------"
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret,
credentials_file = "twitauth.RData")
So far so good. Then in a new R session with twitteR loaded I run load_twitter_oauth("twitauth.RData"). This does not appear to work because I get the following error when trying to do anything that requires me to be authenticated, e.g.:
getCurRateLimitInfo()
[1] "object 'access_token' not found"
Error in twInterfaceObj$doAPICall("application/rate_limit_status", params = params, :
Error: object 'access_token' not found
If instead of starting a new R session I try getCurRateLimitInfo() immediately after setup_twitter_oauth I get a different error:
getCurRateLimitInfo()
[1] "missing value where TRUE/FALSE needed"
Error in twInterfaceObj$doAPICall("application/rate_limit_status", params = params, :
Error: missing value where TRUE/FALSE needed
Am I missing some step in the authentication process here? I get the same problem on my work PC and my personal Mac, both using R version 3.0.2.

Related

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.

twitteR package for R authentication: error 401

Hy everyone/anyone and thank you for considering it!
I'm stuck at the final stage of twitteR package authentication. After a successful cred$handshake as I'm trying to end up the authentication with setup_twitter_oauth, the program keeps throwing the following message:
Error in init_oauth1.0(self$endpoint, self$app, permission =
self$params$permission) : client error: (401) Unauthorized
Any idea what this could be and how could I get around it?
Not sure the precise source of your error, and I had used this package about 2 months ago. I ran into errors doing the handshake as well.
To work-around, I avoided the explicit handshake by using setup_twitter_oauth directly.
consumerKey <- "[your Twitter consumer key]"
consumerSecret <- "[your Twitter consumer secret]"
accessToken <- "[your Twitter access token]"
accessTokenSecret <- "[your Twitter access token secret]"
setup_twitter_oauth(consumerKey, consumerSecret, accessToken, accessTokenSecret)
This seemed to work for me. The various OAuth parameters come from Twitter. I wrote up how to do that here: Newborn app using Twitter and R.
The complete R source code is on BitBucket (the stuff at the bottom is probably most relevant): newborn-app.R.

OAuth authentication is required with Twitter's API v1.1

I am doing my first tweet load into Rstudio to practice some text mining. I am using the twitterR package (with Rcurl).
My code is: rdmTweets <- searchTwitter("#beer", n=500)
But I get:
Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) :
OAuth authentication is required with Twitter's API v1.1
I have Google the error a couple of times, but don't seem to get any helpful results.
Take a look at here. I had the same issue at resolved it this way.
Best,

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!!!

How to access a web service that requires authetication [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Reading information from a password protected site
I have a webservice that provides data in csv form, based on the url you use to access it. i.e. http://sever.com/parameter1 returns a csv for parameter 1, http://sever.com/parameter1 returns a csv for parameter 2, etc. When I first access the site in my browser, I type in a username and password and can then access any data I want.
The problem arises when I try to import that data into R. I tried this function:
readLines('http://sever.com/parameter1')
But got the following error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : cannot open: HTTP status was '401 Unauthorized'
Of course, this is because R doesn't know to pass my username and password along with the request. How do I define these additional parameters in R? Is there any way to add a cookie to the request or something?
Thank you.
/edit: The answer here (different question wording wasn't picked up by SO) worked for me:
Reading information from a password protected site
If anyone else has any other advice, please let me know.
Why don't you use curl to grab the file? That way you can set http headers for username and password:
curl --user name:password http://www.example.com
There is a curl library for R
http://curl.haxx.se/libcurl/r/

Resources