<- get_favorites("DrAmandaRP", n = 5, token = token) favorites
I love that Twitter recently came out with bookmarks! My previous MO on Twitter was to ❤️ posts that contain information that I want to keep for later, most of which are #rstats tweets. I now have 700+ likes, which are time consuming to browse through when I need to find something. I didn’t find an easy way to search likes within Twitter itself, so I built a shiny app to do that using the rtweet
and shiny
R packages.
rtweet
Package
To grab the tweets, there is a little setup with Twitter that is necessary. The setup is described on the rtweet
website.
During setup, I ran into a bit of an issue authenticating my Twitter app. I’m working in RStudio on an AWS instance (via a Chromebook), which has a known issue. The issue and its work-around are described by the package author here. After that speed bump was crossed, the rtweet
package was extremely easy to use!
My Twitter Likes
To get a Twitter user’s favorites (aka likes), use the get_favorites
function. Below I’m going to grab my most recent five favorites:
The resulting tibble has 91 columns!
For fun, here is a wordcloud composed of all of my Twitter likes (created using the tidytext
and wordcloud2
packages):
library(wordcloud2)
library(tidytext)
<- get_favorites("DrAmandaRP", n = 1000, token = token)
favorites %>%
favorites select(text) %>%
unnest_tokens(word, text) %>%
count(word, sort = TRUE) %>%
anti_join(stop_words) %>%
filter(!word %in% c("t.co", "https", "http")) %>%
wordcloud2()
shiny app for searching
I zeroed in on the following fields: status_id
, created_at
, text
, hashtags
, name
, screen_name
. I put them in a table in a shiny app for easy browsing. Check it out here! It’s nothing fancy, but I think it’s going to come in handy.
If you’d like to make your own app, my code is available on GitHub.
It would also be nice to add functionality to search Twitter bookmarks, but apparently at the time of this post, reading bookmarks isn’t yet available in the Twitter API. I’m keeping an eye on this rtweet
issue for updates.