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?
This is a hack and doesn't directly retrieve the OAuth object from setup_twitter_oauth , but it works (adapted from http://www.datablog.sytpp.net/2014/04/scraping-twitter-with-r-a-how-to/).
Do the below once after you've setup your consumer_key and consumer_secret
When mixing TwitteR and streamR, use twitCred as the OAuth for streamR calls
Sample test streamR call to retrieve Tweets relating to football
Use
readRDS()
Access the environment in the list through
$long-alphanumeric-hash
and within that access$credentials
and$oauth_token
/$oauth_token_secret