Skip to content

Instantly share code, notes, and snippets.

@noamross
Last active August 29, 2015 14:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noamross/1046e67762c59183dd7b to your computer and use it in GitHub Desktop.
Save noamross/1046e67762c59183dd7b to your computer and use it in GitHub Desktop.
I wanted to make a list of my disease ecology followers and followees on twitter, so...
library(twitteR)
library(rlist)
library(pipeR)
library(stringi)
# Authenticate with twitter
# consumer/access keys and secrets for the twitter API must be defined elsewhere
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
# Get all my followers and followees
nr = getUser('noamross')
followers = nr$getFollowers()
followees = nr$getFriends()
tweeps = list.merge(followers, followees)
# search across all user descriptions and extract names and descriptions
term = "(disease|parasite|outbreak|spillover|infect|pathology)"
disease_tweeps = tweeps %>>%
list.filter(stri_detect_regex(.$description, term, case_insensitive=TRUE)) %>>%
list.map(list(name = .$screenName, description = .$description)) %>>%
list.stack()
#making lists isn't part of the twitteR packages functionality
#instead I re-authenticate and POST to the twitter API directly
library(httr)
app <- oauth_app("twitter", key = consumer_key, secret = consumer_secret)
sig = sign_oauth1.0(app, access_token, access_secret)
list_response = POST("https://api.twitter.com/1.1/lists/create.json?name=Disease&mode=public&description=disease%20ecologists", sig)
add_list_members_url = paste0('https://api.twitter.com/1.1/lists/members/create_all.json?screen_name=',
paste(disease_tweeps$name, collapse=","),
"&list_id=", content(list_response)$id)
members_response = POST(add_list_members_url, sig)
## See the list at https://twitter.com/noamross/lists/disease/members
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment