Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving cached oauth token with packages httr, twitteR, and streamR

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?

like image 263
user2987808 Avatar asked Dec 16 '14 09:12

user2987808


1 Answers

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

like image 182
Louis Maddox Avatar answered Oct 12 '22 07:10

Louis Maddox