Find your favorite Twitter user with the rtweet package
Aug 25, 2019
Christopher Yee
1 minute read

Do you know who your favorite person on Twitter is? Probably!

Did you ever want to quantify that statement? Probably not!

Are you curious to find out who someone else’s favorite Twitter user is? Now you can with R!

The code below is brought to you by Namita and her hilarious tweet:

Load packages

library(tidyverse)
library(rtweet)

Get Twitter API key

create_token(
  app = "app_name",
  consumer_key = "consumer_key",
  consumer_secret = "consumer_secret",
  access_token = "access_token",
  access_secret = "access_secret"
)

Grab data

twitter_handle <- "eeysirhc"

get_favorites(twitter_handle, n = 3000) %>% 
  group_by(screen_name) %>% 
  tally(sort = TRUE, name = '# of tweets liked') %>% 
  slice(1:10)
## # A tibble: 10 x 2
##    screen_name  `# of tweets liked`
##    <chr>                      <int>
##  1 eywu                          16
##  2 drob                          15
##  3 lauralippay                   13
##  4 dataandme                     11
##  5 coreyeulas                     8
##  6 CMastication                   7
##  7 JHTScherck                     7
##  8 nick_eubanks                   7
##  9 jackiecchu                     6
## 10 ohgm                           5

Future article: grabbing the top 10 favorite users of my top 10 favorite users and then creating a network graph to identify strong/weak relationships.