Rscript, Error check twitter oauth - r

I run the following script using RStudio and twitter package
api_key <- " xxx "
api_secret <- " yyy"
access_token <- "zzz"
access_token_secret <- "mmm"
options(httr_oauth_cache=T)
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
The script works fine, when I run it from Rstudio. However, when I automatically run it via a bat file using Rscript, I get the following error-message:
“Using direct authentication”
Error en check_twitter_oauth() OAuth authentication error:…
Any help will be much appreciate it.

Thanks I find the solution, just need to put the path to the libraries library('xxx',lib= 'C:/Program Files/R/R-3.2.1/library')

Related

TwitteR scraping with R error, fixing ideas?

I'm a bit desperate with my problem as I checked all the existing sources and nothing worked for me.
The issue:
I'm trying to scrape twitter with R in Rstudio, I'm on the very first stage of auth with API keys:
library(twitteR)
library(ROAuth)
library(openssl)
library(httpuv)
library(devtools)
origop <- options("httr_oauth_cache")
options(httr_oauth_cache = TRUE)
api_key <- "*****"
api_secret <- "******"
access_token <- "*****"
access_secret <- "******"
setup_twitter_oauth(api_key, api_secret, access_token, access_secret)
I'm using keys with essential access, v2 access level (which in theory shouldn't be the reason for the bug, but who knows?..)
This code gives the error:
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
What I tried:
1. Restarting the session after installing the packages
2. Fixing httr bug by running:
library(devtools)
devtools::install_version("httr", version="0.6.0", repos="http://cran.us.r-project.org")
3. Fixing possible compatibility issue by running:
devtools::install_github("jrowen/twitteR", ref = "oauth_httr_1_0")
4. running all of the above, restarting R and even restarting the laptop 3 times.
5. Checked my firewall - it's off.
6. Checked my default browser and being logged in in it into twitter - done.
7. Tried re-generating my access keys and re-running all of the above - didn't help.
I don't know what else to try, does anybody have any idea how to fix this issue?
Thanks a million in advance!
Aright, so after some checking here's the solution (if anybody ever needs it):
use library (rtweet)
apply and get approved for elevated access. That was definitely the problem that didn't let me go ahead.

In R: git2r_remote_ls': Failed to retrieve list of SSH authentication methods

I have an issue on installing packages from this private gitlab account. I generated public and private keys through PuTTYgen and used it to communicate with above website. Here is the piece of code I used from the website:
install.packages("devtools")
install.packages("git2r")
library(devtools)
library(git2r)
creds <- git2r::cred_ssh_key("~/.ssh/id_rsa.pub", "~/.ssh/id_rsa")
pkglist <- c("AIRSpec", "Rfunctools", "APRLspec", "APRLmpf", "APRLmvr", "APRLssb")
for(pkg in pkglist) {
print(paste("Installing package:", pkg, "..."))
## install package
devtools::install_git(sprintf("git#gitlab.com:aprl/%s.git", pkg),
credentials = creds)
## install dependencies
descr <- readLines(file.path(.libPaths(), pkg, "DESCRIPTION"))
deps <- strsplit(sub("^Imports: ", "", grep("^Imports: ", descr,
value=TRUE)), ", ")
if (exist("deps$1")) install.packages(deps[[1]])
}
However, I get this error message:
"Error: Failed to install 'unknown package' from Git: Error in 'git2r_remote_ls': Failed to retrieve list of SSH authentication methods: Failed getting response"
Any help or suggestion is appreciated!
Nourolah
I had the same problem, I found this github issue, that issue is filled for the python bindings of libgit2. They propose to generate the ssh keys in the PEM format via:
ssh-keygen -m PEM
That worked for me.
For me, the issue was the permissions of the .ssh files. Fixing the files permissions solved the issue.

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

Rfacebook package, "fbOAuth(appid, appsecret)" fails to get an access token. Returns bad request (HTTP 400)

I am trying to scrape some text from fb using the 'Rfacebook' package.
Even after installing Rfacebook & tm, running relevant libraries (Rfacebook, httr, tm, and httpuv), fboAuth(appid, appsecret) is failing to get the reqd. access token. Please see the code and ensuing error below:
install.packages("Rfacebook")
install.packages("tm")
library(devtools)
library(Rfacebook)
library(httr)
library(httpuv)
library(tm)
appid <- 123
appsecret <- 'mysecret123'
fboauth <- fbOAuth(appid, appsecret, extended_permissions = T)
Which returns
Copy and paste into Site URL on Facebook App Settings:
http://localhost:1410/
When done, press any key to continue...
Upon pasting the redirect url in the cell here, a browser opened.
And, although the browser displayed "Authentication complete. Please close this page and return to R.", an error msg was returned in the RStudio console (attached below.) Again, I tried this with Safari as well as Chrome as default browsers - no change.
Authentication complete.
Error in init_oauth2.0(self$endpoint, self$app, scope = self$params$scope, :
Bad Request (HTTP 400). Failed to get an access token.
Any help in resolving this is truly appreciated!
Best,
S
p.s. Using R-Studio v3.3.2 on a Mac (OS Sierra.)
Try the following
a) remove httr package
b) remove RCurl package
c) remove RFacebook
d) Reinstall httr , then RCurl, and then RFacebook
e) get the latest version of R studio
f) After you authenticate, and when you get the message Copy and paste into Site URL on Facebook App Settings: http://localhost:1410/ When done, press any key to continue...
You may want to do save(user_fbOauth) where user_fbOauth are your credentials
g) then pass them to any other request
I have tried this and dont see any issues

How to send email from R and windows 7

I'm trying to send an email from R. I'm running windows 7 and it does not recognize the sendmailR package. Please help!!
Error in library(sendmailR) : there is no package called ‘sendmailR’
library(sendmailR)
Error in library(sendmailR) : there is no package called ‘sendmailR’
library(mail)
Error in library(mail) : there is no package called ‘mail’
Thank you for your time.
If you are off and running, great. But this might also assist. A very helpful person sent me this description for how to send emails with R. His last name was Kristjborn, from Sweden, but I can't otherwise credit him.
Steps needed, after signing up at postmarkapp.com and getting Hadley's script at https://gist.github.com/hadley/5707759
Copy your API key from postmarkapp.com (in Credentials tab under your server name)
In R, write:
Sys.setenv(POSTMARKAPP_API_KEY= your-copied-api-key-here)
Sys.setenv(POSTMARKAPP_API_KEY= “xxxx”) # with quotes
In the file from which you want to send the email, use the following code:
source('../postmarkapp.r') #or the path to your postmarkapp.r wherever you store it
source("C:/Users/R/Documents/R/R Scripts/sendgmailwithpostmarkfromHadleygist.R")
mailtext <- "Good morning, \nThis should be sending you emails from R in no time. \nBest regards, \nSender"
send_email(to = '...', from = '...', subject = '...', body = mailtext, attachments = 'path-to-file') # or skip attachments
This should work. However, if the code fails in sourcing the postmarkapp, it is probably due to dependent Libraries. The app depends on:
library(base64enc) library(RJSONIO) library(httr)
If any of these are not installed you need to do so. Note that httr is stored on github which needs to be installed using install_github from the devtools package: http://www.rstudio.com/projects/devtools/

Resources