Mastodon
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
This module provides API integration with Mastodon.
It intends to provide the same services as the Twitter module
- Associate one or more Mastodon accounts with their Drupal user account.
- List toots in different ways thanks to Views.
- A Field type, with its own Formatter.
- Format Mastodon @usernames and #hashtags as links to the Mastodon instance.
- Post to own Mastodon account or a site-wide Mastodon account
- ...
The roadmap is available on the issue queue.
Configuration
Configure OAuth at /admin/config/services/mastodon
- The configuration form will provide, by default:
a client_id, client_secret and authorization URL. - Go to the authorization URL, confirm access, copy
the authorization code and save configuration. - The form will autocomplete the bearer from the access token,
re-save configuration then.
A test of the API will be displayed, getting followers from
the user 1 of your instance.
Using the API
The Mastodon class is available as a Drupal service that uses OAuth
credentials defined from the configuration, in the constructor.
Get it via dependency injection ('mastodon.api') then it is ready to use.
$user = $mastodon->authenticateUser($email, $password);
Or use the static service container when dependency injection is not available.
$mastodon = Drupal::service('mastodon.api'); $user = $mastodon->authenticateUser($email, $password);
Option 1 - use the Mastodon wrapper
Currently there is a WIP to implement API methods as a syntactic sugar
#2920985. The status is in README.md.
$user_id = 1; $followers = $mastodon->getFollowers($user_id, ['limit' => 2]);
Option 2 - use the Mastodon API
You can still use the API endpoints defined via the
Mastodon API documentation.
Currently the scopes are defined as read and write (without follow).
$user_id = 1; $followers = $mastodon->getApi()->get('/accounts/'.$user_id.'/followers', ['limit' => 2]);
