0

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)
user1692342
  • 5,007
  • 11
  • 69
  • 128
  • can you post the code with which you are getting the twitter feed? – NicE May 05 '15 at 10:06
  • have you tried setting the 'access_token' and 'access_secret' arguments in the 'setup_twitter_oauth()' function? Don't need an interactive environment for this ([more here](http://stackoverflow.com/questions/28221405/automated-httr-authentication-with-twitter-provide-response-to-interactive-pro/28332136#28332136)) – NicE May 05 '15 at 12:04
  • @NicE I tried. I get the following error: OAuth has not been registered for this session – user1692342 May 05 '15 at 12:09

1 Answers1

1

I believe you need to use a different authentication model than the interactive login. I'm not an expert on these things unfortunately but it seems that from the Twitter documentation you want "Application-only authentication".

https://dev.twitter.com/oauth/application-only

TARehman
  • 6,659
  • 3
  • 33
  • 60