PHP code example of colorfield / mastodon-api

1. Go to this page and download the library: Download colorfield/mastodon-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

colorfield / mastodon-api example snippets


$name = 'MyMastodonApp';
$instance = 'mastodon.social';
$config = new Colorfield\Mastodon\ConfigurationVO($name, $instance);
$this->api = new MastodonAPI($config);

$timeline = $this->api->getPublicData('/timelines/public');

$timeline = $this->api->get('/timelines/public', [], false);

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

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

$oAuth->config->setScopes([
    OAuthScope::read->name, 
    OAuthScope::write->name, 
    OAuthScope::follow->name,
    OAuthScope::push->name
]);

$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);

$oAuth->authenticateUser($email, $password);

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

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

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