I have been trying to authenticate through ROAuth using the following script:
library("ROAuth")
library("RCurl")
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL = "https://api.twitter.com/oauth/access_token"
authURL = "https://api.twitter.com/oauth/authorize"
cKey<- "Key"
cSecret<- "Secret"
Cred <- OAuthFactory$new(consumerKey=cKey,
consumerSecret=cSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
Every time I enter in this code, I get the error:
Error in Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", : Invalid response from site, please check your consumerKey and consumerSecret and try again.
I am not sure what I am doing wrong. I have made sure every necessary package is up to date by re-installing ROauth and RCurl and checking their version information (ROAuth 0.9.1 and RCurl_1.91-1.1(?) ). After installation, I restarted R (as a possible solution suggested by another post). I copy-pasted and double-checked the consumer key and consumer secret, and I am sure they are correct. Does anyone have any other ideas?
Thank you.
Apparently the handshake method in ROauth was broken but was since fixed. The error message you posted (the same one I'm getting right now) is the same as the one referenced in the following link:
http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2012-February/000059.html
I'm guessing there's still an issue so will see if I can find anything else out...
I can't help with RCurl/ROAuth — but you could try the package ‛httr‛ https://github.com/hadley/httr/ . It comes with a demo how to access Twitter.
Related
Trying to get Twitter authentication to work in R (for analyzing tweets), but RStudio does not respond to the PIN + get error messages.
I use Mac OS X 10.6.8 and RStudio Version 0.98.1091
Here's the code I'm using (incl. placeholders):
install.packages("twitteR")
library(twitteR)
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="my_folder/my_subfolder/http://curl.haxx.se/ca/cacert.pem")
require(twitteR)
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL = "https://api.twitter.com/oauth/access_token"
authURL = "https://api.twitter.com/oauth/authorize"
consumerKey = "xxxx"
consumerSecret = "yyyyy"
Cred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") )
I get this:
"To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=bWNevwJNJUPEzKLJwHQsK2uRLN4At5LO
When complete, record the PIN given to you and provide it here: registerTwitterOAuth(Cred)
Error: Authorization Required"
When I enter the PIN in the console I only get this:
>1234567
[1] 1234567
I then try to run
registerTwitterOAuth(Cred), but get this in the console:
Error in registerTwitterOAuth(Cred) :
oauth has not completed its handshake
Not sure what I am doing wrong or how I can obtain authentication/authorization.
Very thankful for any help on this.
try this
library(httk)
library(httpuv)
#browser based authentication
consumer_key <- "xxxxxxxxxxxxxxxxxxxx"
consumer_secret<- "xxxxxxxxxxxxxxxxxxxxxxxxx"
setup_twitter_oauth(consumer_key, consumer_secret, access_token=NULL,access_secret=NULL)
I used the following for Twitter authentication in Windows OS, and it works fine. Maybe it gives some direction!
library(RCurl)
library(twitteR)
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "insert your consumer key here"
consumerSecret <- "insert your consumer secret here"
twitCred <-OAuthFactory$new(consumerKey=consumerKey,consumerSecret=consumerSecret,requestURL=reqURL,accessURL=accessURL,authURL=authURL)
twitCred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
registerTwitterOAuth(twitCred)
I finally figured it out! The console won't let me copy the url after running the code, so I have to type the url with the unique token by hand. I wasn't aware of this. It's a little cumbersome, but at least it works. I'm running into other problems, which I read elsewhere on StackOverflow, might be a problem with Mac's operative system, so this might be linked to it as well. RStudio doesn't seem to jive to well with Mac.
Thanks for all the help!
Make sure that in the Application Settings of Twitter Developers you entered:
Callback URL: http://127.0.0.1:1410
Sign in with Twitter: Yes
I am attempting to set up a tweet sentiment analysis tool in R, however I keep getting errors in relation to 0Auth not completing it's handshake.
it's using a tutorial that I found online, however I'm new to R and coding in general so I'm stumped.
Any light that can be shed on this would be much appreciated:
install.packages("twitteR")
install.packages("plyr")
install.packages("stringr")
install.packages("ggplot2")
install.packages("streamR")
library(twitteR)
library(ROAuth)
library(plyr)
library(stringr)
library(ggplot2)
## Windows users need to get this file
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL = "https://api.twitter.com/oauth/access_token"
authURL = "https://api.twitter.com/oauth/authorize"
consumerKey = "conkey code"
consumerSecret = "consec code"
Cred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
Cred$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl") )
1340490
load("twitter authentication.Rdata")
registerTwitterOAuth(Cred)
Have you tried looking at the creators github page:(https://github.com/geoffjentry/twitteR/blob/master/README.md) It's an easier way to do it. You will also need to install Rtools if you are going to do it this way. Here is a youtube link that shows you how to install Rtools(https://www.youtube.com/watch?v=enPPMHr5SrM) it is in Chinese but you can still follow what this guy is doing. I hope this helps.
I noticed many threads regarding problems with Twitter API authentication but apparently no one seem relevant to my problem. As soon as I try to authenticate, right after I am asked to enter the PIN, the system throws an error ("Unauthorized"). This happens before I can enter the PIN.
The code is:
library("twitteR")
library("RCurl")
library("ROAuth")
# Set SSL certs globally
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))
Credentials <- OAuthFactory$new(
consumerKey = "XX",
consumerSecret = "XX",
oauthKey = "XX",
oauthSecret = "XX",
requestURL = "https://api.twitter.com/oauth/request_token",
authURL = "https://api.twitter.com/oauth/authorize",
accessURL = "https://api.twitter.com/oauth/access_token")
Credentials$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
And the results is:
To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=XX
When complete, record the PIN given to you and provide it here:
Error: Unauthorized
As mentioned above, this happens before I can actually enter my PIN. I run the script in RStudio but running on classic R GUI does not make any change. I am running R version 3.0.1.
Post Scriptum
I tried different version of the code, for example this one, but I get the exact same error.
You can follow this step:
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "Mjn6tdsadsadkasdklad2SV1l"
consumerSecret <- "58Z7Eldsdfaslkf;asldsaoeorjkfksaVCQtvri"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
twitCred$handshake()
After you run this code you will see in R console message like this :
To enable the connection, please direct your web browser to:
https://api.twitter.com/oauth/authorize?oauth_token=scmVODruosvz6Tdsdadadasdsa
When complete, record the PIN given to you and provide it here:
Just paste the link to your browser then authorize app, last one you will get the PIN code, just copy and paste the PIN code to your R console.
registerTwitterOAuth(twitCred)
R console will show TRUE if you success.
user <- getUser("xxx")
userTimeline(user, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE)
If still any problem just try to show your package version and update to the last version
sessionInfo()
update.packages("twitteR")
The last version for twitteR is 1.1.7 => http://cran.r-project.org/web/packages/twitteR/index.html
You can download twitteR manual => see page number 12 http://cran.r-project.org/web/packages/twitteR/twitteR.pdf
I am using R and want to use the twitteR package available on CRAN.
I installed the twitteR package using:
install.packages(twitteR)
then loaded the package with:
library(twitteR)
after that I wanted to run the first command to get the latest trends on twitter with:
getTrends(period="weekly")
which showed following error:
Error in getTrends(period = "weekly") :
argument "woeid" is missing, with no default
Also the command:
searchTwitter("#orms")
showed an error, namely:
Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) :
OAuth authentication is required with Twitter's API v1.1
And also for the command:
userTimeline("informs")
there was an error output:
Error in twInterfaceObj$doAPICall(cmd, params, method, ...) :
OAuth authentication is required with Twitter's API v1.1
What is the reason for that? From my research so far I figured out, it has something to do with oauth. But actually I don't know, what oauth is, and how to configure it, so I can properly use the twitteR package.
Could please anybody provide me some help for this issue??
Thank you very much in advance for your support.
With best regards!!!
1/ You'll need to load ROAuth, which is a dependency of twitteR. See the twitter CRAN docs. http://cran.r-project.org/web/packages/twitteR/twitteR.pdf
Depends: ... ROAuth (>= 0.9.3) ...
2/ You'll need to authenticate as per the below. See pg12 of the twitteR CRAN docs:
## A real example, but using a fictitious consumerkey and consumer
## secret - you’ll need to supply your own
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"
consumerKey <- "12345pqrst6789ABCD"
consumerSecret <- "abcd1234EFGH5678ijkl0987MNOP6543qrst21"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
twitCred$handshake()
registerTwitterOAuth(twitCred)
In general, you should try to search error messages over the CRAN docs of your package - the answer will often be self-contained.
I'm having a very difficult time getting my OAuth to work so that I can make 350 calls per hour to twitter's API.
I have reviewed several other threads with similar topics, but my problem appears to be different:
twitteR and ROAuth R Packages install
twitteR and ROAuth
TwitteR, ROAuth and Windows: register OK, but certificate verify failed
my code is as follows:
rm(list=ls())
library("twitteR")
library("ROAuth")
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL = "https://api.twitter.com/oauth/access_token"
authURL = "https://api.twitter.com/oauth/authorize"
cKey = "__________"
cSecret = "__________"
Cred <- OAuthFactory$new(consumerKey=cKey,
consumerSecret=cSecret,
requestURL=requestURL,
accessURL=accessURL,
authURL=authURL)
Cred$handshake()
registerTwitterOAuth(Cred)
Despite trying many different versions of the same code, resetting my API key, and even registering a new account and retrieiving a new API key, i continually return this error:
Error in Cred$handshake() :
Invalid response from site, please check your consumerKey and consumerSecret and try again.
There is absolutely no way this could be an issue with my key/secret. Any other ideas?
Problem Solved:
I had already downloaded this new version of ROAuth (http://lists.hexdump.org/pipermail/twitter-users-hexdump.org/2012-February/000059.html) but had not restarted R! duh!