如何保存 twitter 身份验证凭据以在闪亮的应用程序中重复使用? [英] How to save twitter authentication credentials for repeated use in a shiny application?

查看:70
本文介绍了如何保存 twitter 身份验证凭据以在闪亮的应用程序中重复使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 和 Shiny 的新手

I am new to R and Shiny

我正在尝试创建一个简单的闪亮应用程序,它从 twitter api 中提取与搜索词相关的推文.在 R 工作室,要访问 Twitter api 以获取推文,我运行以下代码进行身份验证.

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

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

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

Only after above four lines I can do the actual search as shown below

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

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

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

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

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

Is there someway I could save the authentication credentials so that the app can always be online(running), and the credentials be loaded as and when a search is carried out.

谢谢.

推荐答案

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

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

给予

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

这篇关于如何保存 twitter 身份验证凭据以在闪亮的应用程序中重复使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆