How to save twitter authentication credentials for reuse in shiny app?

I am new to R and Shiny

I am trying to create a simple shiny application that pulls tweets related to a search term from the twitter api. In R Studio, To access the twitter api for tweets, I run the following to authenticate.

> consumer_key<-'value1'
> access_token<-'value3'
> access_secret<-'value4'
> setup_twitter_oauth(consumer_key, consumer_secret, access_token,access_secret)


After only four lines, I can do the actual search like below

tweets <-searchTwitter (search_term, n = input_number, from = start_date, before = end_date, lang = 'en')

(i.e. all values ​​of the variables in the searchTwitter () function are taken from the user)

Is there some way to store the authentication credentials so that the app is always online (running) and the credentials are loaded how and when the lookup was done.



source to share

1 answer

This may not be the best way, but

setup_twitter_oauth(consumer_key = "yourkey", consumer_secret = "yoursecret")
token <- get("oauth_token", twitteR:::oauth_cache)



<oauth_app> twitter
  key:    xxxx
  secret: <hidden>
<credentials> oauth_token, oauth_token_secret, user_id, screen_name, x_auth_expires


Then cache it





All Articles