--- title: "Basic Usage" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Basic_Usage} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- # Introduction Welcome to the `atrrr` vignette! This guide will delve deeper into the functionalities offered by the package- Before diving in, let's clarify some terminology. In the context of Blue Sky, a post is referred to as a "skeet." So, when we mention retrieving or working with "skeets," we are talking about individual posts made on Blue Sky. Now, let's delve deeper into the functionalities that allow users to interact with skeets, followers, and their descriptions. ## Installation If you haven't done so, you can install the development version of atrrr like so (`pak` works similar to `remotes` here, but it's what the cool kids use now :grin:): ``` r # install.packages("pak") pak::pak("JBGruber/atrrr") ``` ## Load the package ``` r library(atrrr) ``` ## Authentication The first time you make a request, you will be prompted automatically to enter your user handle and an app password to authenticate `atrrr` to communicate with BlueSky for you. ![RStudio Popup](figures/password_popup.png) The page to generate app passwords is also automatically opened for you. ![page to create new app passwords](figures/app_password.png) However, you can also trigger this process manually: ``` r auth("jbgruber.bsky.social") ``` This can be useful if you want to replace an old token as it is permanently stored encrypted on disk. # Searching Posts You can search Posts on Bluesky using a small set of operators: - Whitespace is treated as implicit AND, so all words in a query must occur - Double quotes indicate exact phrases - `from:` will filter to results from that account - `-` excludes terms Note that matches can occur anywhere in the skeet, not just the text. For example, a term can be in the link preview, or alt text of an image. A couple of examples: ``` r search_post("rstats") #> # A tibble: 100 × 18 #> uri cid author_handle author_name text author_data post_data embed_data reply_count #> #> 1 at:/… bafy… tterence.bsk… terence "Lig… 0 #> 2 at:/… bafy… emazaola.bsk… "Mor… 0 #> 3 at:/… bafy… rosenetwork.… RoSE Netwo… "🚨N… 0 #> 4 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0 #> 5 at:/… bafy… avehtari.bsk… Aki Vehtar… "The… 1 #> 6 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0 #> 7 at:/… bafy… jimjamslam.b… James Gold… "💡 … 0 #> 8 at:/… bafy… tterence.bsk… terence "Riv… 1 #> 9 at:/… bafy… jeremywallac… Jeremy Wal… "Wel… 0 #> 10 at:/… bafy… cranberriesf… CRAN Packa… "CRA… 0 #> # ℹ 90 more rows #> # ℹ 9 more variables: repost_count , like_count , indexed_at , #> # in_reply_to , in_reply_root , quotes , tags , mentions , #> # links ``` This finds posts where "rstats" is found somewhere in the post. ``` r search_post("#rstats Bluesky") #> # A tibble: 34 × 18 #> uri cid author_handle author_name text author_data post_data embed_data reply_count #> #> 1 at:/… bafy… gdeejay.bsky… Giles "One… 0 #> 2 at:/… bafy… dariia.bsky.… Dariia Myk… "Blu… 0 #> 3 at:/… bafy… o.simardcasa… Olivier Si… "Thi… 16 #> 4 at:/… bafy… thomascwells… Thomas W "Jus… 0 #> 5 at:/… bafy… nrennie.bsky… Nicola Ren… "A r… 0 #> 6 at:/… bafy… o.simardcasa… Olivier Si… "The… 0 #> 7 at:/… bafy… thoughtfulnz… David Hood "Che… 1 #> 8 at:/… bafy… o.simardcasa… Olivier Si… "Wit… 2 #> 9 at:/… bafy… seacatkim.bs… Catherine "Hel… 4 #> 10 at:/… bafy… thoughtfulnz… David Hood "#30… 2 #> # ℹ 24 more rows #> # ℹ 9 more variables: repost_count , like_count , indexed_at , #> # in_reply_to , in_reply_root , quotes , tags , mentions , #> # links ``` This finds posts with the hashtag "rstats" AND the word Bluesky somewhere in the skeet (ignoring capitalisaion). You can also search for the exact phrase "new #rstats package": ``` r search_post("\"new #rstats package\"") #> # A tibble: 17 × 18 #> uri cid author_handle author_name text author_data post_data embed_data reply_count #> #> 1 at:/… bafy… seabbs.bsky.… "Sam Abbot… "New… 1 #> 2 at:/… bafy… coatless.bsk… "James Bal… "Int… 0 #> 3 at:/… bafy… heinersalomo… "Heiner Sa… "Thi… 1 #> 4 at:/… bafy… egorkotov.bs… "Egor Koto… "We'… 0 #> 5 at:/… bafy… egorkotov.bs… "Egor Koto… "Fai… 0 #> 6 at:/… bafy… frodsan.bsky… "Francisco… "Thi… 1 #> 7 at:/… bafy… simonpcouch.… "Simon P. … "🚨N… 0 #> 8 at:/… bafy… posit.co "Posit" "We’… 0 #> 9 at:/… bafy… chriskenny.b… "Chris Ken… "New… 0 #> 10 at:/… bafy… robjhyndman.… "Rob Hyndm… "My … 0 #> 11 at:/… bafy… cghlewis.bsk… "Crystal L… "Whe… 0 #> 12 at:/… bafy… jbgruber.bsk… "Johannes … "New… 1 #> 13 at:/… bafy… mikemahoney2… "Mike Maho… "📣 … 0 #> 14 at:/… bafy… mikemahoney2… "Mike Maho… "Exc… 0 #> 15 at:/… bafy… jbgruber.bsk… "Johannes … "New… 1 #> 16 at:/… bafy… pciarchaeolo… "" "2/3… 1 #> 17 at:/… bafy… eddelbuettel… "Dirk Edde… "Eve… 0 #> # ℹ 9 more variables: repost_count , like_count , indexed_at , #> # in_reply_to , in_reply_root , quotes , tags , mentions , #> # links ``` ``` r #' # Use single quotes so you do not need to escape double quotes #' search_post('"new #rstats package"') ``` You can also limit your search by only looking for skeets from one user: ``` r search_post("from:jbgruber.bsky.social #rstats") #> # A tibble: 31 × 18 #> uri cid author_handle author_name text author_data post_data embed_data reply_count #> #> 1 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0 #> 2 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0 #> 3 at:/… bafy… jbgruber.bsk… Johannes B… "Tes… 0 #> 4 at:/… bafy… jbgruber.bsk… Johannes B… "lla… 1 #> 5 at:/… bafy… jbgruber.bsk… Johannes B… "I t… 1 #> 6 at:/… bafy… jbgruber.bsk… Johannes B… "I j… 1 #> 7 at:/… bafy… jbgruber.bsk… Johannes B… "I a… 1 #> 8 at:/… bafy… jbgruber.bsk… Johannes B… "Che… 1 #> 9 at:/… bafy… jbgruber.bsk… Johannes B… "For… 0 #> 10 at:/… bafy… jbgruber.bsk… Johannes B… "My … 0 #> # ℹ 21 more rows #> # ℹ 9 more variables: repost_count , like_count , indexed_at , #> # in_reply_to , in_reply_root , quotes , tags , mentions , #> # links ``` # Blue Sky Users and Skeets ## Retrieve user info (`get_user_info`) A good starting point is understanding a user's digital footprint on the platform. The get_user_info function becomes our handy tool, fetching an array of information about a user. All you need? Their handle! ``` r get_user_info(actor = "atpr.bsky.social") |> dplyr::glimpse() #> Rows: 1 #> Columns: 8 #> $ did "did:plc:j42kj4qc5vfz344weywpkair" #> $ indexed_at 1-01-01 #> $ actor_handle "atpr.bsky.social" #> $ actor_name NA #> $ actor_description NA #> $ actor_avatar NA #> $ viewer_data [FALSE, FALSE, "at://did:plc:ntd53albt5ffa4rgervvgibd/app.bsky.graph.… #> $ labels_data [] ``` This function gives us counts of followers, follows, posts for each user. You can also retrieve information for multiple users by providing a vector of user handles: ``` r get_user_info(actor = c("benguinaudeau.bsky.social", "atpr.bsky.social")) |> dplyr::glimpse() #> Rows: 2 #> Columns: 8 #> $ did "did:plc:vuvsifrusnjsys7mhkpk662u", "did:plc:j42kj4qc5vfz344weywpkair" #> $ indexed_at 2024-01-26 01:28:47, 1-01-01 00:00:00 #> $ actor_handle "benguinaudeau.bsky.social", "atpr.bsky.social" #> $ actor_name "Benjamin Guinaudeau", NA #> $ actor_description "Postdoc @CSMaP_NYU. \n\nPolitics, data science, and hacking stuff in… #> $ actor_avatar "https://cdn.bsky.app/img/avatar/plain/did:plc:vuvsifrusnjsys7mhkpk6… #> $ viewer_data [FALSE, FALSE, "at://did:plc:ntd53albt5ffa4rgervvgibd/app.bsky.graph.… #> $ labels_data [], [] ``` ## Retrieve Skeets (`get_skeets_authored_by`) To fetch all the skeets by a specific user, use the `get_skeets_authored_by` function. *Note this also includes quote skeets and reskeets.* You can also opt not to parse the result by setting `parse = FALSE`, however it is recommended to use the default parse option which results in a (more) tidy tibble. ``` r get_skeets_authored_by(actor = "benguinaudeau.bsky.social", parse = TRUE) |> dplyr::glimpse() #> Rows: 25 #> Columns: 19 #> $ uri "at://did:plc:f5jstfwgvzacfsdjjdia4466/app.bsky.feed.post/3knyr4ydsqb2w",… #> $ cid "bafyreieqiqwb4wwzosmx4jg3cee5ob2guc6qnjswkridxokkh23fm6wghq", "bafyreiab… #> $ author_handle "jacobmontgomery.bsky.social", "beamagistro.bsky.social", "jbgruber.bsky.… #> $ author_name "I jacob, the pumpkin king 🎃 👑 ", "Beatrice Magistro", "Johannes B. Gru… #> $ text "Seriously? Not a single woman instructor, presenter, or organizer for a … #> $ author_data ["did:plc:f5jstfwgvzacfsdjjdia4466", "jacobmontgomery.bsky.social", "I j… #> $ post_data ["app.bsky.feed.post", "2024-03-18T21:09:28.158Z", ["app.bsky.embed.exte… #> $ embed_data ["app.bsky.embed.external#view", ["https://www.law.northwestern.edu/rese… #> $ reply_count 0, 0, 1, 4, 0, 0, 4, 0, 1, 9, 0, 1, 0, 1, 0, 0, 0, 0, 1, 12, 0, 0, 1, 1, 1 #> $ repost_count 3, 6, 6, 8, 0, 0, 15, 2, 1, 431, 3, 1, 5, 28, 0, 0, 0, 0, 0, 289, 14, 1, … #> $ like_count 13, 12, 20, 13, 1, 1, 42, 6, 1, 609, 7, 3, 10, 35, 1, 0, 1, 3, 2, 453, 37… #> $ indexed_at 2024-03-18 21:09:28, 2024-02-16 17:26:58, 2024-01-10 15:23:18, 2024-01-04… #> $ in_reply_to NA, NA, NA, NA, NA, "at://did:plc:eotrvt2wp6mqooxjf3bzklwa/app.bsky.feed… #> $ in_reply_root NA, NA, NA, NA, NA, "at://did:plc:eotrvt2wp6mqooxjf3bzklwa/app.bsky.feed.… #> $ quotes NA, NA, "at://did:plc:vgvueqvmbqgoyxtcdebqdcgb/app.bsky.feed.post/3kin4vi… #> $ tags , , "rstats", "rstats", , , , , "AoE"… #> $ mentions , , , , , , , , , … #> $ links , , , , , , , , , … #> $ is_reskeet TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TR… ``` Feeling adventurous? Increase the `limit` and explore more of their content. ``` r get_skeets_authored_by(actor = "favstats.bsky.social", limit = 30) |> dplyr::glimpse() #> Rows: 30 #> Columns: 19 #> $ uri "at://did:plc:7ao77wemnhl63qnpuy7psebr/app.bsky.feed.post/3l55lu5ebts24",… #> $ cid "bafyreibgmqfbgls7rvgusnr4k6arykcsmwvxkpiev6nlh5pel5inx3lusa", "bafyreiea… #> $ author_handle "whotargetsme.bsky.social", "whotargetsme.bsky.social", "favstats.bsky.so… #> $ author_name "Who Targets Me", "Who Targets Me", "Fabio Votta📊🐧 ", "Johannes B. Grub… #> $ text "Interesting how Democrats and Republicans are competing to target Latino… #> $ author_data ["did:plc:7ao77wemnhl63qnpuy7psebr", "whotargetsme.bsky.social", "Who Ta… #> $ post_data ["app.bsky.feed.post", "2024-09-27T16:36:15.797Z", ["app.bsky.embed.imag… #> $ embed_data ["app.bsky.embed.images#view", [["https://cdn.bsky.app/img/feed_thumbnai… #> $ reply_count 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0… #> $ repost_count 1, 1, 0, 8, 5, 0, 2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0… #> $ like_count 1, 2, 2, 13, 5, 0, 1, 10, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10… #> $ indexed_at 2024-09-27 16:36:15, 2024-09-27 16:38:18, 2024-09-19 16:33:57, 2024-09-1… #> $ in_reply_to NA, "at://did:plc:7ao77wemnhl63qnpuy7psebr/app.bsky.feed.post/3l55lu5ebts… #> $ in_reply_root NA, "at://did:plc:7ao77wemnhl63qnpuy7psebr/app.bsky.feed.post/3l55lu5ebts… #> $ quotes NA, NA, NA, NA, NA, NA, "at://did:plc:46yyakot3byghwqc6rhmqzqd/app.bsky.f… #> $ tags , , , , , , , , , … #> $ mentions , , , , , , , , , … #> $ links , , , , , , , , , … #> $ is_reskeet TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, F… ``` ## Who liked your Skeets? The get_likes function allows you to extract detailed information about users who liked a specific post. By simply providing the post's URL, you can get a list of users who expressed their appreciation for the content. ``` r get_likes("https://bsky.app/profile/ryanlcooper.com/post/3kb42gayda52t") |> dplyr::glimpse() #> Rows: 25 #> Columns: 5 #> $ created_at 2024-02-29 22:14:52, 2024-02-26 13:03:05, 2024-02-23 23:38:41, 2024-01-25… #> $ indexed_at 2024-02-29 22:14:52, 2024-02-26 13:03:05, 2024-02-23 23:38:41, 2024-01-25… #> $ actor_handle "dsfpspacefl1ght.bsky.social", "demonchuckle.bsky.social", "butpawwwlll.bs… #> $ actor_name "David S. F. Portree, quasi-retired writer, archivist, & educator", "Demon… #> $ actor_data ["did:plc:b3igxlkvw5hbsjxurrv2xb74", "dsfpspacefl1ght.bsky.social", "Davi… ``` ## Who reposted your Skeets? Reposts (or reskeets), akin to retweets on platforms like Twitter, amplify the reach of content by sharing it with a wider audience. The `get_reposts` function is designed to retrieve information about users who reposted a specific piece of content. ``` r get_reposts(post_url = "https://bsky.app/profile/ryanlcooper.com/post/3kb42gayda52t") |> dplyr::glimpse() #> Rows: 25 #> Columns: 8 #> $ did "did:plc:zyvmwfzbkt3igdqgpemu3pot", "did:plc:zyb3zoeo2snrj6ugwirudqys… #> $ indexed_at 2024-01-26 00:03:39, 2024-01-26 00:35:53, 2024-03-21 11:54:36, 2024-… #> $ actor_handle "zunguzungu.bsky.social", "bertierustle.bsky.social", "gebi.bsky.soci… #> $ actor_name "Aaron Bady", "Bertie Rustle", "Michael Gebetsroither", "Amanda Katz"… #> $ actor_description "Meat blood, bees, things of that nature", "Mouthy leftist/Giver Godd… #> $ actor_avatar "https://cdn.bsky.app/img/avatar/plain/did:plc:zyvmwfzbkt3igdqgpemu3p… #> $ viewer_data [FALSE, FALSE], [FALSE, FALSE], [FALSE, FALSE], [FALSE, FALSE], [FAL… #> $ labels_data [], [], [], [], [], [], [], [], [["did:plc:zrrfehir5gdxoapcddwea2fg"… ``` # Exploring Connections: Get Followers and Follows You can retrieve a list of followers and those followed by a user through the `get_followers` and `get_follows` functions, respectively. This gives a glimpse of their social dynamics on the platform. ## `get_followers` ``` r get_followers(actor = "benguinaudeau.bsky.social", limit = 200) |> dplyr::glimpse() #> Rows: 299 #> Columns: 8 #> $ did "did:plc:c27h545kxtb7yyh7zg3jkdsm", "did:plc:l3rfgtccdg3lkqg3nbhgnwk3… #> $ indexed_at 2024-09-18 05:31:06, 2024-09-21 22:04:38, 2024-09-18 07:22:44, 2024-… #> $ actor_handle "goodword2654.bsky.social", "andreucasas.bsky.social", "earth-pic.bsk… #> $ actor_name "좋은글", "Andreu Casas", "Earth pic", "Anton Strezhnev", "Lawrence M… #> $ actor_description "매일 아침 마음을 깨우는 시 한 편\n꽃처럼 아름다운 하루가 당신에게 꽃… #> $ actor_avatar "https://cdn.bsky.app/img/avatar/plain/did:plc:c27h545kxtb7yyh7zg3jkd… #> $ viewer_data [FALSE, FALSE], [FALSE, FALSE, "at://did:plc:ntd53albt5ffa4rgervvgib… #> $ labels_data [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], … ``` ## `get_follows` ``` r atrrr:::get_follows(actor = "benguinaudeau.bsky.social", limit = 200) |> dplyr::glimpse() #> Rows: 173 #> Columns: 8 #> $ did "did:plc:3ryku2cbgpazorytvt6lt273", "did:plc:miczfsfixolk42l7343z3bpd… #> $ indexed_at 2024-02-08 05:16:04, 2024-01-25 23:49:49, 2024-01-25 23:51:33, 2024-… #> $ actor_handle "beamagistro.bsky.social", "sethcotlar.bsky.social", "aoc.bsky.social… #> $ actor_name "Beatrice Magistro", "Seth Cotlar", "Alexandria Ocasio-Cortez", "CRAN… #> $ actor_description "PostDoc @Caltech, thru @UofT. Poli Sci PhD \n@UW-Seattle. 🇮🇹🇪🇺🇺🇸🇨🇦, … #> $ actor_avatar "https://cdn.bsky.app/img/avatar/plain/did:plc:3ryku2cbgpazorytvt6lt2… #> $ viewer_data [FALSE, FALSE], [FALSE, FALSE], [FALSE, FALSE], [FALSE, FALSE, "at:/… #> $ labels_data [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], … ``` You'll notice each follower/following has a description (i.e. their bio). It's a nifty way to get to know a bit about them at a glance! ## Follower Network Visualization This section guides you through the process of visualizing a follower network for a given user on Blue Sky. The primary focus is on the "skeets" (posts) and the interconnected relationships among followers. The first step is to load some additional packages. Then we get the followers for the main user we are interested in. We will then delve deeper and fetch the followers for each of these followers. ``` r library(ggplot2) library(dplyr) library(purrr) library(tidyr) library(igraph) library(ggraph) library(tidygraph) # Retrieve the followers for the main user some_followers <- get_followers(actor = "benguinaudeau.bsky.social", limit = 10)$actor_handle # For each follower, retrieve their own set of followers. # This provides a nested view of relationships. followers_of_followers <- some_followers |> purrr::map_dfr(~{ get_followers(actor = .x, limit = 200) |> mutate(from = .x) }) |> dplyr::rename(to = actor_handle) |> dplyr::select(from, to) ``` ## Building and Visualizing the Follower Network ``` r # Construct the network graph and plot graph <- igraph::graph_from_data_frame(followers_of_followers, directed = TRUE) # Use ggraph to visualize the network. ggraph::ggraph(graph, layout = "kk") + ggraph::geom_edge_link() + ggraph::geom_node_point(aes(size = tidygraph::centrality_pagerank())) + ggplot2::theme_void() ```
Follower Network

Follower Network

## Find people to follow You can use a similar approach to find new people you might want to follow. First get all the people you already follow by quering your own account: ``` r my_follows <- get_follows(actor = "jbgruber.bsky.social", limit = 10)$actor_handle # limit only for demonstration # For each account you follow, retrieve who they follow. follows_of_follows <- my_follows |> purrr::map_dfr(~{ get_followers(actor = .x, limit = 100) |> mutate(from = .x) }) # Now we can check which accounts are popular among the people you already follow follows_of_follows |> dplyr::filter(!actor_handle %in% my_follows) |> # exclude accounts you already follow dplyr::count(actor_name, actor_handle, sort = TRUE) #> # A tibble: 1,393 × 3 #> actor_name actor_handle n #> #> 1 "Johannes B. Gruber" jbgruber.bsky.social 7 #> 2 "Analytical Sociology" iasliu.bsky.social 3 #> 3 "Jihed Ncib" jihedncib.bsky.social 3 #> 4 "Prof David Farrell, UCD" davidfarrell-ucd.bsky.social 3 #> 5 "" ab4aba.bsky.social 2 #> 6 "" uupeace.bsky.social 2 #> 7 "Alexandre Raffoul" awraffoul.bsky.social 2 #> 8 "Allison Koh" allisonwkoh.bsky.social 2 #> 9 "Amar jeet" amarjeat.bsky.social 2 #> 10 "Andreas Hövermann " andreashoev.bsky.social 2 #> # ℹ 1,383 more rows ``` The original account shows up in this overview, as do accounts that were excluded because of the limit set to do the demonstration. But all of these accounts look intresting!