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'
>consumer_secret<-'value2'
> 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.

Thank.

+3


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)
token

      

Gives



<Token>
<oauth_endpoint>
 request:   https://api.twitter.com/oauth/request_token
 authorize: https://api.twitter.com/oauth/authenticate
 access:    https://api.twitter.com/oauth/access_token
<oauth_app> twitter
  key:    xxxx
  secret: <hidden>
<credentials> oauth_token, oauth_token_secret, user_id, screen_name, x_auth_expires
---

      

Then cache it

token$cache()

      

+3


source







All Articles