Last active
April 26, 2018 03:02
-
-
Save maelle/a18562eefd05aa65e284ac057f0ffbc4 to your computer and use it in GitHub Desktop.
How to follow all members of the unconf18 Twitter 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script! This was my first time using
rtweet
^^. Just a minor note, I had to delete thetoken = twitter_token
arg (to use theNULL
default) in order to use the .Renviron setup from the first link in your script.