Where does twitteR PIN code appear during R oauth authentication? - r

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.
I use this code to register my credentials:
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 then get the link to twitter:
To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=xxxx
I follow the link and within the twitter page, and then click on the “Authorize app” button. This sends me back to the site I listed as the callback URL.
I don’t see the PIN number I was expecting anywhere. My question is: where does it appear? Or where should I be looking for it? I feel like this should be obvious, but somehow I'm missing it.

I had similar problems, and had to make two changes.
1 - change all https to http as mentioned by SimonO101
2 - make sure to delete the callback URL - otherwise rather than displaying the PIN is simply moved on to the callback URL destination

Related

Access to Twitter Streaming APIs Using R using streamR & ROAuth

I am attempting to connect to Twitter's Streaming API in R. My code (including a fake consumer key and secret) is as follows:
library(streamR)
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 <- "xxxxxxxyyyyyyyyzzzzzzzz"
consumerSecret <- "xxxxxxxyyyyyyyyzzzzzzzz123123123123123"
my_oauth <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret, requestURL=requestURL,
accessURL=accessURL, authURL=authURL)
my_oauth$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
When I enter this code, I get the following message (although I have altered the web address):
To enable the connection, please direct your web browser to:
http://api.twitter.com/oauth/authorize?oauth_token=xxxxxxxyyyyyyyyzzzzzzzz
When complete, record the PIN given to you and provide it here:
The next thing I see is the following screen in my browser:
I select "Authorize app", and I am navigated away from api.twitter.com. I never see the PIN that I need in order to progress forward.
Any ideas regarding how to solve this problem (and retrieve the PIN that I need in order to enable the connection I'm trying to create) are welcome!
I removed the callback URL and this solved the problem.
You just need to enter the pin into your RSTudio Console

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.

Finding the PIN from Twitter.Com after using twitteR library on R and ROAuth package

I have a question that I hope someone could help me with.
I am trying to get some tweets from Twitter via R, using the twitteR library and the other required packages. I have successfully created my code up to the handshake. But as soon as I reach the point where I am supposed to copy and paste a link to get the required PIN, I am redirected to the placeholder website address I have registered with Twitter.
Below is my block of code:
cred <- OAuthFactory$new (consumerKey = consumerKey, consumerSecret = consumerSecret, requestURL = "http://api.twitter.com/oauth/request_token", accessURL = "http://api.twitter.com/oauth/access_token", authURL = "http://api.twitter.com/oauth/authorize")
cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
This then leads to a prompt
To enable the connection, please direct your web browser to: http://api.twitter.com/oauth/authorize?oauth_token=_______________________
I have tried several of the answers in Stackoverflow.Com such as No PIN generated when using ROAuth to authenticate on Twitter, Where does twitteR PIN code appear during R oauth authentication? but no success.
Any response will be really helpful.
Thanks.
BTW: R Noob and basic programmer.
To avoid to be redirected to the placeholder website and see your PIN.
You should :
go back to your twitter app https://apps.twitter.com/app/
in the settings, erase the placeholder website address you gave
save
Next time you will use http://api.twitter.com/oauth/authorize?oauth_token=xxxx
and click on "authorize", you will see the PIN.

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

Oauth with Twitter Streaming API in R (using RCurl)

I would like to connect to Twitter's Streaming API using RCurl in R, and also be able to filter keywords. However, new restrictions on authorization in Twitter API v1.1 is making using RCurl difficult.
Before, code could go something like this taken from this page:
getURL("https://stream.twitter.com/1/statuses/filter.json",
userpwd="Username:Password",
cainfo = "cacert.pem",
write=my.function,
postfields="track=bruins")
But now, Twitter's new API is making users authorize with OAuth. I have a token and secret, I just need to place it in this code for authorization.
Thanks!
You can do it with pacakge ROAuth. I assume you have registered your app with Twitter and have an API key. I pieced this together from other questions on Stack Overflow (that question and associated answers also contains some links to other contributing questions) and the documentation for package ROAuth and twitteR.
library(RCurl)
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 = "myconsumerkeystring"
consumerSecret = "myconsumersecretstring"
Cred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
#The next command provides a URL which you will need to copy and paste into your favourite browser
#Assuming you are logged into Twitter you will then be provided a PIN number to type into the R command line
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") )
# Checks that you are authorised
registerTwitterOAuth(Cred)
I believe that use of the streaming API is handled by the package streamR
HTH

Resources