Last active
December 8, 2016 16:54
-
-
Save herbps10/c9d49865554de0a759337b5f7fd50657 to your computer and use it in GitHub Desktop.
Twitter Bulk Add to List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Adds twitter users to a twitter list in bulk | |
# | |
library(twitteR) | |
query <- "#EHSFEST" | |
screen_name <- "herbps10" | |
list_slug <- "ehsfest" | |
setup_twitter_oauth(consumer_key = "...", consumer_secret = "...") | |
results <- searchTwitter(query, n = 1000) | |
df <- twListToDF(results) | |
groups <- split(unique(df$screenName), ceiling(seq_along(unique(df$screenName)) / 80)) %>% | |
purrr::map(paste, collapse=",") | |
for(str in groups) { | |
params <- list( | |
slug = list_slug, | |
screen_name = str, | |
owener_screen_name = screen_name | |
) | |
resp <- POST("https://api.twitter.com/1.1/lists/members/create_all.json", | |
config = config(token = get("oauth_token", twitteR:::oauth_cache)), | |
query = params, | |
encode = "form") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment