使用包 httr、twitteR 和 streamR 检索缓存的 oauth 令牌 [英] Retrieving cached oauth token with packages httr, twitteR, and streamR
问题描述
我发现通过 Twitter API 验证自己的唯一方法如下:
图书馆(twitteR)setup_twitter_oauth(consumer_key = "a",消费者秘密 = "b",access_token = "c",access_secret = "d")
运行这个后,我可以使用twitteR中的所有功能就好了.但是,我也想使用 streamR 包,它需要令牌作为 OAuth 对象:
filterStream("tweets.json", track = c("Obama", "Biden"), timeout = 20, oauth=my_oauth)
据我所知,上面的 setup_twitter_oauth 函数是一些 httr 函数的包装器,用于获取我的授权令牌.此令牌作为名为.httr-oauth"的文件缓存在我的工作目录中.我的问题是:如何将此文件加载到 R 中,以便获得可与 streamR 一起使用的 OAuth 对象?
使用 readRDS()
通过$long-alphanumeric-hash
访问列表中的环境,并在该访问中$credentials
和$oauth_token
/$oauth_token_secret
The only way I've found to get myself authenticated with the twitter API is the following:
library(twitteR)
setup_twitter_oauth(consumer_key = "a",
consumer_secret = "b",
access_token = "c",
access_secret = "d")
After running this, I can use all functions in twitteR just fine. However, I would also like to use the streamR package, which needs the token as an OAuth object:
filterStream("tweets.json", track = c("Obama", "Biden"), timeout = 20, oauth=my_oauth)
From what I gather, the setup_twitter_oauth function above is a wrapper around some httr functions to get my authorization token. This token is cached in my working directory as a file called ".httr-oauth". My question is: how do I load this file into R, such that I get an OAuth object that I can use with streamR?
Use readRDS()
readRDS('.httr-oauth') $xxxx0x000xxxx00000x0xx0x000000xx request: https://api.twitter.com/oauth/request_token authorize: https://api.twitter.com/oauth/authenticate access: https://api.twitter.com/oauth/access_token twitter key: xxxxxxxxxx0xxxxxxxxxxxxxx secret: oauth_token, oauth_token_secret, user_id, screen_name
Access the environment in the list through $long-alphanumeric-hash
and within that access $credentials
and $oauth_token
/$oauth_token_secret
这篇关于使用包 httr、twitteR 和 streamR 检索缓存的 oauth 令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!