I am trying to a R script through command line which connects to twitter. When I run the code through R-Studio it is able to connect to twitter and get the tweets. However when I run the script through command line I get the following error:
Error: oauth_listener() needs an interactive environment.
To resolve this, I ran once through R-studio and saved the environment variables in the following manner:
if(file.exists("./token_file"))
{
load("./token_file")
}
else
{
token <- setup_twitter_oauth(consumerKey,consumerSecret,access_token=NULL, access_secret=NULL)
save(token,file="./token_file")
}
Now I get an error:
Error in get_oauth_sig() : OAuth has not been registered for this session
I tried saving the authentication session as well by:
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
if(file.exists("./auth_file"))
{
load("./auth_file")
}
else
{
my_oauth <- OAuthFactory$new(consumerKey = consumerKey, consumerSecret = consumerSecret,
requestURL = requestURL, accessURL = accessURL, authURL = authURL)
save(my_oauth,file ="./auth_file")
}
However I still get the above mentioned error. Is there a way to get R to connect to twitter through command line?
I am using twitteR
package.
I search for stream in twitter by using the function
searchTwitter("love", n=10)