1resource_families = c("account", "application", "blocks", "direct_message", "favorites", "followers", 2 "friends", "friendships", "geo", "help", "lists", "saved_searches", "search", 3 "statuses", "trends", "users") 4 5getCurRateLimitInfo <- function(resources=resource_families, ...) { 6 if ((length(resources) == 0) || (!all(resources %in% resource_families))){ 7 stop("Must provide at least one valid resource family: ", 8 paste(resource_families, collapse=", ")) 9 } 10 params = list() 11 if (length(resources) > 0) { 12 params[["resources"]] = paste(resources, collapse=",") 13 } 14 json <- twInterfaceObj$doAPICall("application/rate_limit_status", params=params, ...) 15 if (! "resources" %in% names(json)) { 16 stop("Invalid response from server - no 'resources' field in JSON") 17 } 18 resources = unlist(json[["resources"]], recursive=FALSE) 19 resource_names = sapply(strsplit(names(resources), "\\."), function(x) x[2]) 20 resource_rows = lapply(resources, function(x) { 21 return(c(limit=x$limit, remaining=x$remaining, reset=twitterDateToPOSIX(x$reset))) 22 }) 23 resource_matrix = cbind(resource=resource_names, do.call(rbind, resource_rows)) 24 rownames(resource_matrix) = NULL 25 resource_df = as.data.frame(resource_matrix, stringsAsFactors=FALSE) 26 resource_df[, "reset"] = as.POSIXct(as.numeric(resource_df[, "reset"]), tz="UTC", origin="1970-01-01") 27 return(resource_df) 28 } 29 30get_authenticated_user = function(...) { 31 buildUser(twInterfaceObj$doAPICall("account/verify_credentials", ...)) 32} 33 34can_access_other_account = function(other_id) { 35 # The idea here is to first get our own username, and then make sure that we're 36 # following screenName if they're protected. If they're protected and we're not 37 # following, we can't see their details 38 authenticated_user_id = get_authenticated_user()$getId() 39 if (authenticated_user_id != other_id) { 40 other_user = getUser(other_id) 41 if (other_user$getProtected()) { 42 relationship = friendships(user_ids = other_id) 43 return(relationship[1, "following"]) 44 } 45 } 46 47 TRUE 48} 49 50