r programming --- twitteR OAuthFactory object error - r

I am setting up an R session to be able to download twitter feeds. I got stumbled on the very step with R citing 'object OAuthFactory not found'. I have all the libraries needed for the program and packages installed: Here is my code
my.key <- "xxx"
#consumer secret
my.secret <- "xxx"
cred <- OAuthFactory$new(consumerKey=my.key, consumerSecret=my.secret,
requestURL = 'https://api.twitter.com/oauth/request_token',
accessURL = 'https://api.twitter.com/oauth/access_token',
authURL = 'https://api.twitter.com/oauth/authorize')
Error: object 'OAuthFactory' not found
Thanks for your help in advance!

I did some more research and found that I had to install two more packages that were not part of the twitteR package. Here is what I needed and it worked:
install.packages(c('ROAuth','RCurl'))
require('ROAuth')
require('RCurl')
Thx

Related

RTweet OAuth Error in Configuration

I know literally zero about the R programming language and have come to an impasse where I am truly and utterly stuck.
I've borrowed lots of other peoples code and have been busy debugging placing in additional libraries that are not contained within the help text of the packages to get to a point I feel is tantalisingly close.
That said I simply cannot get R to correctly authorise a twitter search or OAuth Connection.
I run my code, it throws up the following error screen.
Alongside that in the R-Compiler the error message of
twitCred$handshake() To enable the connection, please direct your web
browser to:
http://api.twitter.com/oauth/authorize?oauth_token=r4VjQQAAAAAA4-K7AAABYlMXEws
When complete, record the PIN given to you and provide it here:
registerTwitterOAuth(twitCred) Error: Forbidden
I read that there can be issues with the call back if the weblinks within the code do not read https:// and are left with http:// so that has been amended accordingly to no avail.
My twitter settings are as follows
I followed the advice laid down in this thread but it didn't seem to help or I did something I wasn't supposed to.... StackOverflow Support Article
So here is my code please shout if you can see the obvious to you not to me error or can offer some advice.
## install devtools package if it's not already
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
## install dev version of rtweet from github
devtools::install_github("mkearney/rtweet")
## load rtweet package
library(rtweet)
install.packages("rtweet")
install.packages("RCurl")
install.packages("tm")
install.packages("wordcloud")
install.packages("httpuv")
install.packages(c('ROAuth','RCurl'))
install.packages("rjson")
install.packages("bit64")
install.packages("httr")
require(twitteR)
require(RCurl)
require(tm)
require(wordcloud)
require(httpuv)
require(rtweet)
require(ROAuth)
require(RCurl)
require(rjson)
require(bit64)
require(httr)
## CURL LOGIC ##
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
api_key <- "AAAAAAA"
consumer_key <- "AAAAAAA"
consumerKey <- "AAAAAAA"
consumerSecret <- "AAAAAAA"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
access_token <- "AAAAAAA"
access_token_secret <- "AAAAAAAAAA"
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
twitCred$handshake()
registerTwitterOAuth(twitCred)
##################
The duplications of API keys are meant to be there as I have tried so many connection advice threads and am lost now on the hows whys and wherefores...
You can use the twitteR package for data mining Twitter.
Please find the below code for your reference.
install.packages('twitteR')
install.packages('ROAuth')
install.packages("RCurl")
library(twitteR)
require("ROAuth")
require("RCurl")
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
t_consumer_key<- 'YOUR CONSUMER KEY'
t_consumer_secret<- 'YOUR CONSUMER SECRET KEY'
t_access_token<- 'YOUR ACCESS TOKEN'
t_access_secret <- 'YOUR ACCESS SECRET'
setup_twitter_oauth(t_consumer_key,t_consumer_secret,t_access_token,t_access_secret)
list <- searchTwitter("iphone")
If you click on the link in below image you will get all the API keys

OAUTH issues with twitteR package

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.

strsplit error when attempting to access Fitbit with ROAuth

I am attempting to access the fitbit API using ROAuth but keep falling at the first hurdle.
Here is my code:
library(ROAuth)
reqURL <- "https://api.fitbit.com/oauth/request_token"
accessURL <- "https://api.fitbit.com/oauth/access_token"
authURL <- "https://www.fitbit.com/oauth/authorize"
cKey <- "xxxxx"
cSecret <- "xxxxx"
credentials <- OAuthFactory$new(consumerKey=cKey,
consumerSecret=cSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
credentials$handshake()
Running this gives the following rather cryptic error:
Error in strsplit(response, "&") : non-character argument
Any suggestions, greatly appreciated!
Following the suggestion of #hadley rather than solving the ROAuth problem, I have switched to using the httr package instead. The code in this question worked for me.

ROAuth handshake

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.

ROAuth and twitteR, Mac OS X 10.7, R 2.15

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!

Resources