All Projects → colorfield → mastodon-api-php

colorfield / mastodon-api-php

Licence: Apache-2.0 License
PHP wrapper for the Mastodon API.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to mastodon-api-php

guzzle-oauth2-subscriber
OAuth 2.0 Client for Guzzle 4, 5, 6 and 7 with PHP 5.4 - PHP 8.0 - no more dependency hell!
Stars: ✭ 112 (+833.33%)
Mutual labels:  oauth, guzzle
The-PHP-Workshop
A New, Interactive Approach to Learning PHP
Stars: ✭ 30 (+150%)
Mutual labels:  composer, guzzle
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (+408.33%)
Mutual labels:  composer, guzzle
Mailchimp Api 3.0 Php
A feature rich object-oriented PHP library for interacting with MailChimp's API v3 💌🐵
Stars: ✭ 61 (+408.33%)
Mutual labels:  oauth, composer
PhpBotFramework
A framework for Telegram Bot API written in PHP.
Stars: ✭ 56 (+366.67%)
Mutual labels:  composer, guzzle
php-mime-detector
Detect a file's mime type using magic numbers.
Stars: ✭ 20 (+66.67%)
Mutual labels:  composer
phabricator-extensions
Github mirror of "phabricator/extensions" - our actual code is hosted in phabricator
Stars: ✭ 13 (+8.33%)
Mutual labels:  oauth
REST-Api-with-Slim-PHP
REST API with PHP Slim Framework 3 and MySQL
Stars: ✭ 69 (+475%)
Mutual labels:  composer
database
Aplus Framework Database Library
Stars: ✭ 147 (+1125%)
Mutual labels:  composer
unit-converter
Convert standard units from one to another with this easy to use, lightweight package
Stars: ✭ 104 (+766.67%)
Mutual labels:  composer
httpx-oauth
Async OAuth client using HTTPX
Stars: ✭ 55 (+358.33%)
Mutual labels:  oauth
awps-cli
Nifty Command Line Application to quickly setup a new AWPS theme in WordPress
Stars: ✭ 25 (+108.33%)
Mutual labels:  composer
validation
Aplus Framework Validation Library
Stars: ✭ 99 (+725%)
Mutual labels:  composer
cli
Aplus Framework CLI Library
Stars: ✭ 104 (+766.67%)
Mutual labels:  composer
Spotify
[READ ONLY] Subtree split of the SocialiteProviders/Spotify Provider (see SocialiteProviders/Providers)
Stars: ✭ 13 (+8.33%)
Mutual labels:  oauth
Vulnerable-OAuth-2.0-Applications
vulnerable OAuth 2.0 applications: understand the security implications of your OAuth 2.0 decisions.
Stars: ✭ 224 (+1766.67%)
Mutual labels:  oauth
mastodon.js
Javascript Mastodon API for Web Browsers with streaming support
Stars: ✭ 32 (+166.67%)
Mutual labels:  mastodon-api
mediastack
All in one Docker Compose media server
Stars: ✭ 42 (+250%)
Mutual labels:  oauth
RaccoonWP
Modern Architecture Stack and Starter Theme for WordPress
Stars: ✭ 17 (+41.67%)
Mutual labels:  composer
laravel-dingtalk
✨基于laravel5.5开发的钉钉机器人、支持多个钉钉群
Stars: ✭ 18 (+50%)
Mutual labels:  composer

Mastodon API PHP

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

Build Status

Getting started

Install it via Composer.

composer require colorfield/mastodon-api

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.
  2. Get an instance from the instance list.

Quick test

oAuth

An interactive demo is available.

  1. Clone the GitHub repository.
  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
  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

Authorize your application

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

Authenticate with oAuth

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.

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

  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

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

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

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

Get followers

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

Post

Clear notifications

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

@todo complete with delete and stream.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].