如何保存 Twitter 身份验证凭据以在闪亮的应用程序中重复使用?

How to save twitter authentication credentials for repeated use in a shiny application?

我是 R 和 Shiny 的新手

我正在尝试创建一个简单的闪亮应用程序,用于从 Twitter api 中提取与搜索词相关的推文。 在 R Studio 中, 要访问 twitter api 以获取推文,我 运行 以下内容用于身份验证。

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

只有在上面四行之后,我才能进行如下所示的实际搜索

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

( 即 searchTwitter() 函数中变量的所有值都取自用户)

有什么方法可以保存身份验证凭据,以便应用程序始终在线(运行ning),并在执行搜索时加载凭据。

谢谢。

这可能不是最好的方法,但

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

给予

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

然后缓存它

token$cache()