Skip to content

Instantly share code, notes, and snippets.

@maelle
Last active April 26, 2018 03:02
Show Gist options
  • Save maelle/a18562eefd05aa65e284ac057f0ffbc4 to your computer and use it in GitHub Desktop.
Save maelle/a18562eefd05aa65e284ac057f0ffbc4 to your computer and use it in GitHub Desktop.
How to follow all members of the unconf18 Twitter list
# First step is to authenticate yourself see http://rtweet.info/articles/auth.html
# your username
who <- "ma_salmon"
# Users I already follow
following <- rtweet::get_friends(users = who)
# Users from the list
unconf18 <- rtweet::lists_members(slug = "ropensci-runconf18",
owner_user = "ropensci")
# do not follow oneself either thanks Jim Hester
unconf18 <- unconf18[unconf18$screen_name != who,]
# I should watch https://speakerdeck.com/jennybc/row-oriented-workflows-in-r-with-the-tidyverse
unconf18 <- split(unconf18, unconf18$user_id)
follow_if_not_already_followed <- function(user_df){
if(user_df$user_id %in% following$user_id){
message(paste0("Oh I already follow ", user_df$name, " alias @", user_df$screen_name))
}else{
message(paste0("Posting the following of...", user_df$name, " alias @", user_df$screen_name))
rtweet::post_follow(user_df$user_id,
token = twitter_token)
message(paste0("NOW I do follow ", user_df$name, " alias @", user_df$screen_name))
Sys.sleep(2)
}
}
purrr::walk(unconf18, follow_if_not_already_followed)
# Gist created with gistr https://github.com/ropensci/gistr
@lcolladotor
Copy link

Thanks for the script! This was my first time using rtweet ^^. Just a minor note, I had to delete the token = twitter_token arg (to use the NULL default) in order to use the .Renviron setup from the first link in your script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment