PHPackages                             afterlogic/mastodon-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. afterlogic/mastodon-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

afterlogic/mastodon-api
=======================

PHP wrapper for Mastodon API

0.1.1(3y ago)01391Apache-2.0PHPPHP &gt;=5.6.0

Since Oct 13Pushed 2y agoCompare

[ Source](https://github.com/afterlogic/mastodon-api-php)[ Packagist](https://packagist.org/packages/afterlogic/mastodon-api)[ Docs](https://github.com/r-daneelolivaw/mastodon-api-php)[ RSS](/packages/afterlogic-mastodon-api/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

Mastodon API PHP
================

[](#mastodon-api-php)

PHP wrapper for the Mastodon API that includes oAuth helpers, Guzzle based.

[![Build Status](https://camo.githubusercontent.com/26d95aed654eb655fe2b6534d2d469ee1a797a00b507f986fc39b5ab123fe467/68747470733a2f2f7472617669732d63692e6f72672f722d64616e65656c6f6c697661772f6d6173746f646f6e2d6170692d7068702e706e67)](https://travis-ci.org/r-daneelolivaw/mastodon-api-php)

Getting started
---------------

[](#getting-started)

Install it via Composer.

`composer require colorfield/mastodon-api`

Mastodon API and instances
--------------------------

[](#mastodon-api-and-instances)

This is a plain API wrapper, so the intention is to support further changes in the API by letting the developer pass the desired endpoint.

1. Get the [REST Mastodon documentation](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md).
2. Get an instance from the [instance list](https://instances.mastodon.xyz/list).

Quick test
----------

[](#quick-test)

### oAuth

[](#oauth)

An interactive demo is available.

1. Clone the [GitHub repository](https://github.com/r-daneelolivaw/mastodon-api-php).
2. cd in the cloned directory
3. Run `composer install`
4. Run `php -S localhost:8000`
5. In your browser, go to [http://localhost:8000/test\_oauth.php](http://localhost:8000/test_oauth.php)
6. You will get the client\_id and client\_secret, click on the authorization URL link, then confirm the authorization under Mastodon and copy the authorization code.
7. Get the bearer: click on the "Get access token" button.
8. Authenticate with your Mastodon username (email) and password: click on "Login".

[![Authorize your application](documentation/images/mastodon-authorize.png?raw=true "Authorize your application")](documentation/images/mastodon-authorize.png?raw=true)

[![Authorize your application](documentation/images/mastodon-authorization-code.png?raw=true "Authorization code")](documentation/images/mastodon-authorization-code.png?raw=true)

### Mastodon API

[](#mastodon-api)

1. Make your own copy of *test\_credentials.example.php* as *test\_credentials.php*
2. Define in *test\_credentials.php* the information obtained with oAuth and your Mastodon email and password.
3. In your browser, go to [http://localhost:8000/test\_api.php](http://localhost:8000/test_api.php)

Authenticate with oAuth
-----------------------

[](#authenticate-with-oauth)

### Register your application

[](#register-your-application)

Give it a name and an optional instance. The instance defaults to mastodon.social.

```
$name = 'MyMastodonApp';
$instance = 'mastodon.social';
$oAuth = new Colorfield\Mastodon\MastodonOAuth($name, $instance);

```

The default configuration is limited the the 'read' and 'write' scopes. You can modify it via

`$oAuth->config->setScopes(['read', 'write', 'follow']);`

Note that this must be done while obtaining the token so you cannot override this after. [More about scopes](https://github.com/tootsuite/documentation/blob/master/Using-the-API/OAuth-details.md).

### Get the authorization code

[](#get-the-authorization-code)

1. Get the authorization URL `$authorizationUrl = $oAuth->getAuthorizationUrl();`
2. Go to this URL, authorize and copy the authorization code.

### Get the bearer

[](#get-the-bearer)

1. Store the authorization code in the configuration value object. `$oAuth->config->setAuthorizationCode(xxx);`
2. Then get the access token. As a side effect, stores it on the configuration value object. `$oAuth->getAccessToken();`

Use the Mastodon API
--------------------

[](#use-the-mastodon-api)

### Instantiate the Mastodon API with the configuration

[](#instantiate-the-mastodon-api-with-the-configuration)

The oAuth credentials should be stored from the configuration value object for later retrieval. Then you can use it in this way.

```
$name = 'MyMastodonApp';
$instance = 'mastodon.social';
$oAuth = new Colorfield\Mastodon\MastodonOAuth($name, $instance);
$oAuth->config->setClientId('...');
$oAuth->config->setClientSecret('...');
$oAuth->config->setBearer('...');
$mastodonAPI = new Colorfield\Mastodon\MastodonAPI($oAuth->config);

```

### User login

[](#user-login)

Login with Mastodon email and password. `$oAuth->authenticateUser($email, $password);`

### Use the API wrapper

[](#use-the-api-wrapper)

Here are a few examples of the API wrapper usage. Read the [full documentation](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md).

#### Get

[](#get)

Get credentials

`$credentials = $mastodonAPI->get('/accounts/verify_credentials');`

Get followers

`$followers = $mastodonAPI->get('/accounts/USER_ID/followers');`

#### Post

[](#post)

Clear notifications

`$clearedNotifications = $mastodonAPI->post('/notifications/clear');`

@todo complete with delete and stream.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~131 days

Recently: every ~196 days

Total

7

Last Release

1303d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4507359?v=4)[Afterlogic Corp.](/maintainers/afterlogic)[@afterlogic](https://github.com/afterlogic)

---

Top Contributors

[![colorfield](https://avatars.githubusercontent.com/u/525003?v=4)](https://github.com/colorfield "colorfield (28 commits)")[![sash04ek](https://avatars.githubusercontent.com/u/10223169?v=4)](https://github.com/sash04ek "sash04ek (7 commits)")[![vasil-sokolov](https://avatars.githubusercontent.com/u/17827771?v=4)](https://github.com/vasil-sokolov "vasil-sokolov (1 commits)")

---

Tags

phpapirestmastodon

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/afterlogic-mastodon-api/health.svg)

```
[![Health](https://phpackages.com/badges/afterlogic-mastodon-api/health.svg)](https://phpackages.com/packages/afterlogic-mastodon-api)
```

###  Alternatives

[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.7M17](/packages/xeroapi-xero-php-oauth2)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34216.9k2](/packages/onesignal-onesignal-php-api)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1830.8k2](/packages/huaweicloud-huaweicloud-sdk-php)[colorfield/mastodon-api

PHP wrapper for Mastodon API

293.1k1](/packages/colorfield-mastodon-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
