Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gesistsa/rtoot
:mammoth: R package to interact with the mastodon API
https://github.com/gesistsa/rtoot
mastodon mastodon-api rstats rstats-package
Last synced: about 5 hours ago
JSON representation
:mammoth: R package to interact with the mastodon API
- Host: GitHub
- URL: https://github.com/gesistsa/rtoot
- Owner: gesistsa
- License: other
- Created: 2022-11-05T20:26:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-06T19:34:32.000Z (about 2 months ago)
- Last Synced: 2024-12-17T09:54:17.086Z (6 days ago)
- Topics: mastodon, mastodon-api, rstats, rstats-package
- Language: R
- Homepage: https://gesistsa.github.io/rtoot/
- Size: 6.51 MB
- Stars: 105
- Watchers: 6
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# rtoot
[![CRAN status](https://www.r-pkg.org/badges/version/rtoot)](https://CRAN.R-project.org/package=rtoot)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/rtoot)](https://CRAN.R-project.org/package=rtoot)
[![R-CMD-check](https://github.com/gesistsa/rtoot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gesistsa/rtoot/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/gesistsa/rtoot/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gesistsa/rtoot?branch=main)Interact with the [mastodon API](https://docs.joinmastodon.org/api/) from R.
Get started by reading `vignette("rtoot")`.Please cite this package as:
Schoch, D. & Chan, C-h., (2023). Rtoot: Collecting and Analyzing Mastodon Data. Mobile Media & Communication, [https://doi.org/10.1177/20501579231176678](https://doi.org/10.1177/20501579231176678).
For a BibTeX entry, use the output from `citation("rtoot")`.
## Installation
To get the current released version from CRAN:
```{r eval = FALSE}
install.packages("rtoot")
```You can install the development version of rtoot from GitHub:
```{r install, eval=FALSE}
remotes::install_github("gesistsa/rtoot")
```## Authenticate
First you should set up your own credentials (see also `vignette("auth")`)
```{r aut, eval=FALSE}
auth_setup()
```
The mastodon API allows different access levels. Setting up a token with your own account grants you the most access.## Instances
In contrast to twitter, mastodon is not a single instance, but a federation of different servers.
You sign up at a specific server (say "mastodon.social") but can still communicate with others from other servers (say "fosstodon.org"). The existence of different instances makes API calls more complex.
For example, some calls can only be made within your own instance (e.g `get_timeline_home()`), others can access all instances but you need to specify the instance as a parameter (e.g. `get_timeline_public()`).A list of active instances can be obtained with `get_fedi_instances()`. The results are sorted by number of users.
General information about an instance can be obtained with `get_instance_general()`
```{r, eval = FALSE}
get_instance_general(instance = "mastodon.social")
````get_instance_activity()` shows the activity for the last three months and `get_instance_trends()` the trending hashtags of the week.
```{r, eval = FALSE}
get_instance_activity(instance = "mastodon.social")
get_instance_trends(instance = "mastodon.social")
```## Get toots
To get the most recent toots of a specific instance use `get_timeline_public()`
```{r, eval = FALSE}
get_timeline_public(instance = "mastodon.social")
```To get the most recent toots containing a specific hashtag use `get_timeline_hashtag()`
```{r, eval = FALSE}
get_timeline_hashtag(hashtag = "rstats", instance = "mastodon.social")
```The function `get_timeline_home()` allows you to get the most recent toots from your own timeline.
```{r, eval = FALSE}
get_timeline_home()
```## Get accounts
`rtoot` exposes several account level endpoints. Most require the account id instead of the username as an input. There is, to our knowledge, no straightforward way of obtaining the account id. With the package you can get the id via `search_accounts()`.
```{r, eval=FALSE}
search_accounts("schochastics")
```*(Future versions will allow to use the username and user id interchangeably)*
Using the id, you can get the followers and following users with `get_account_followers()` and
`get_account_following()` and statuses with `get_account_statuses()`.```{r, eval = FALSE}
id <- "109302436954721982"
get_account_followers(id)
get_account_following(id)
get_account_statuses(id)
```## Posting statuses
You can post toots with:
```{r, eval = FALSE}
post_toot(status = "my first rtoot #rstats")
```It can also include media and alt_text.
```{r, eval = FALSE}
post_toot(
status = "my first rtoot #rstats", media = "path/to/media",
alt_text = "description of media"
)
```You can mark the toot as sensitive by setting `sensitive = TRUE` and add a spoiler text with `spoiler_text`.
*(Be aware that excessive automated posting is frowned upon (or even against the ToS) in many instances. Make sure to check the ToS of your instance and be mindful when using this function.)*
## Streaming
`rtoot` allows to stream statuses from three different streams.
To get any public status on any instance use `stream_timeline_public()`
```{r, eval = FALSE}
stream_timeline_public(timeout = 30, file_name = "public.json")
```
the timeout parameter is the time in seconds data should be streamed (set to `Inf` for indefinite streaming). If just the local timeline is needed, use `local=TRUE` and set an instance (or use your own provided by the token).`stream_timeline_hashtag()` streams all statuses containing a specific hashtag
```{r, eval = FALSE}
stream_timeline_hashtag("rstats", timeout = 30, file_name = "rstats_public.json")
```The statuses are directly written to file as json. The function `parse_stream()` can be used
to read in and convert a json to a data frame.## Pagination
All relevant functions in the package support pagination of results if the `limit` parameter is larger than the default page size (which is 40 in most cases). In this case, you may get more results than requested since the pages are always fetched as a whole. If you for example request 70 records, you will get 80 back, given that many records exist.
## Code of Conduct
Please note that the rtoot project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). By contributing to this project, you agree to abide by its terms.