1getTwitterOAuth = function(consumer_key, consumer_secret) { 2 stop("ROAuth is no longer used in favor of httr, please see ?setup_twitter_oauth") 3} 4 5registerTwitterOAuth <- function(oauth) { 6 stop("ROAuth is no longer used in favor of httr, please see ?setup_twitter_oauth") 7} 8 9check_twitter_oauth = function() { 10 req = try(stop_for_status(GET("https://api.twitter.com/1.1/account/settings.json", 11 config(token=get_oauth_sig()))), silent=TRUE) 12 13 if (inherits(req, "try-error")) { 14 stop("OAuth authentication error:\nThis most likely means that you have incorrectly called setup_twitter_oauth()'") 15 } 16} 17 18get_twitter_token_via_sign = function(app, access_token, access_secret) { 19 print("Using direct authentication") 20 params <- list(as_header = TRUE) 21 credentials <- list(oauth_token = access_token, 22 oauth_token_secret = access_secret) 23 twitter_token <- Token1.0$new(endpoint = NULL, params = params, 24 app = app, credentials = credentials) 25 26 if (is.null(twitter_token)) 27 stop("Invalid response for twitter_token") 28 29 twitter_token 30} 31 32get_twitter_token_via_browser = function(app, ...) { 33 print("Using browser based authentication") 34 oauth1.0_token(oauth_endpoints('twitter'), app) 35} 36 37setup_twitter_oauth = function(consumer_key, consumer_secret, access_token=NULL, access_secret=NULL) { 38 app <- oauth_app("twitter", key=consumer_key, secret=consumer_secret) 39 40 if (is.null(access_token) || is.null(access_secret)) { 41 token_func = get_twitter_token_via_browser 42 } else { 43 token_func = get_twitter_token_via_sign 44 } 45 46 twitter_token = token_func(app, access_token, access_secret) 47 assign("oauth_token", twitter_token, envir=oauth_cache) 48 49 check_twitter_oauth() 50} 51 52use_oauth_token = function(twitter_token) { 53 assign("oauth_token", twitter_token, envir=oauth_cache) 54} 55 56has_oauth_token = function() { 57 exists("oauth_token", envir=oauth_cache) 58} 59 60get_oauth_sig = function() { 61 if (!has_oauth_token()) { 62 stop("OAuth has not been registered for this session") 63 } 64 65 return(get("oauth_token", envir=oauth_cache)) 66} 67