Download the PHP package afterlogic/mastodon-api without Composer
On this page you can find all versions of the php package afterlogic/mastodon-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download afterlogic/mastodon-api
More information about afterlogic/mastodon-api
Files in afterlogic/mastodon-api
Package mastodon-api
Short Description PHP wrapper for Mastodon API
License Apache-2.0
Homepage https://github.com/r-daneelolivaw/mastodon-api-php
Informations about the package mastodon-api
Mastodon API PHP
PHP wrapper for the Mastodon API that includes oAuth helpers, Guzzle based.
Getting started
Install it via Composer.
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.
- Get the REST Mastodon documentation.
- Get an instance from the instance list.
Quick test
oAuth
An interactive demo is available.
- Clone the GitHub repository.
- cd in the cloned directory
- Run
composer install
- Run
php -S localhost:8000
- In your browser, go to http://localhost:8000/test_oauth.php
- 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.
- Get the bearer: click on the "Get access token" button.
- Authenticate with your Mastodon username (email) and password: click on "Login".
Mastodon API
- Make your own copy of _testcredentials.example.php as _testcredentials.php
- Define in _testcredentials.php the information obtained with oAuth and your Mastodon email and password.
- In your browser, go to http://localhost:8000/test_api.php
Authenticate with oAuth
Register your application
Give it a name and an optional instance. The instance defaults to mastodon.social.
The default configuration is limited the the 'read' and 'write' scopes. You can modify it via
Note that this must be done while obtaining the token so you cannot override this after. More about scopes.
Get the authorization code
- Get the authorization URL
$authorizationUrl = $oAuth->getAuthorizationUrl();
- Go to this URL, authorize and copy the authorization code.
Get the bearer
-
Store the authorization code in the configuration value object.
$oAuth->config->setAuthorizationCode(xxx);
- Then get the access token. As a side effect, stores it on the configuration value object.
$oAuth->getAccessToken();
Use the Mastodon API
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.
User login
Login with Mastodon email and password.
$oAuth->authenticateUser($email, $password);
Use the API wrapper
Here are a few examples of the API wrapper usage. Read the full documentation.
Get
Get credentials
Get followers
Post
Clear notifications
@todo complete with delete and stream.