- PHP >= 8.2
- Laravel >= 10.0
composer require revolution/laravel-mastodon-api
- Go to your Mastodon's user preferences page.
- Go to development page.
use Revolution\Mastodon\Facades\Mastodon;
class MastodonController
{
public function app()
{
$client_name = 'my-app';
$redirect_uris = 'https://my-instance/callback';
$scopes = 'read write follow';
$app_info = Mastodon::domain('https://example.com')
->createApp($client_name, $redirect_uris, $scopes);
dd($app_info);
//[
// 'id' => '',
// 'client_id' => '',
// 'client_secret' => '',
//]
}
}
Use https://github.com/kawax/socialite-mastodon
Save account info.(id
, token
, username
, acct
...and more.)
use Revolution\Mastodon\Facades\Mastodon;
$statuses = Mastodon::domain('https://example.com')
->token('token')
->statuses($account_id);
dd($statuses);
use Revolution\Mastodon\Facades\Mastodon;
$status = Mastodon::domain('https://example.com')
->token('token')
->status($status_id);
dd($status);
use Revolution\Mastodon\Facades\Mastodon;
Mastodon::domain('https://example.com')->token('token');
$response = Mastodon::createStatus('test1');
$response = Mastodon::createStatus('test2', ['visibility' => 'unlisted']);
dd($response);
use Revolution\Mastodon\Facades\Mastodon;
$response = Mastodon::domain('https://example.com')
->token('token')
->get('/timelines/public', ['local' => true]);
use Revolution\Mastodon\Facades\Mastodon;
$response = Mastodon::domain('https://example.com')
->token('token')
->post('/follows', ['uri' => '']);
use Revolution\Mastodon\Facades\Mastodon;
$response = Mastodon::domain('https://example.com')
->token('token')
->call('DELETE', '/statuses/1');
Check public methods in Contracts/Factory.php
Edit $token
and $url
in streaming_example.php
php ./streaming_example.php
Ctrl+C
to quit.
MIT