PHP code example of keinos / mastodon-streaming-api-listener

1. Go to this page and download the library: Download keinos/mastodon-streaming-api-listener 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/ */

    

keinos / mastodon-streaming-api-listener example snippets




 = [
    // Your Mastodon server URL
    'url_host' => 'https://qiitadon.com/',
];

$listener = new \KEINOS\MSTDN_TOOLS\Listener\Listener($conf);

/**
 * $listener ............ The iterator.
 *   $event_name ........ Event name. ("update" or "delete")
 *   $data_payload ...... Data of the event in JSON string.
 */
foreach($listener as $event_name => $data_payload) {
    echo 'Event name: ' . $event_name . PHP_EOL;
    echo 'Data: '. PHP_EOL;
    print_r(json_decode($data_payload));
}




ias \KEINOS\MSTDN_TOOLS\Listener\Listener as Listener
use KEINOS\MSTDN_TOOLS\Listener\Listener;

$conf = [
    'url_host' => 'https://qiitadon.com/',
    // If the server is in "whitelist-mode" then you'll need an access token.
    'access_token' => 'YOUR_ACCESS_TOKEN',
];

$listener = new Listener($conf);

foreach($listener as $event_name => $data_payload) {
    echo 'Event name: ' . $event_name . PHP_EOL;
    echo 'Data: '. PHP_EOL;
    print_r(json_decode($data_payload));
}




EINOS\MSTDN_TOOLS\Listener\Listener;

$conf = [
    'url_host' => 'https://qiitadon.com/',
    // To listen the local time line stream set 'local'. 'public' is the default.
    'type_stream' => 'local',
];

$listener = new Listener($conf);

foreach($listener as $event_name => $data_payload) {
    echo 'Event name: ' . $event_name . PHP_EOL;
    echo 'Data: '. PHP_EOL;
    print_r(json_decode($data_payload));
}