keinos/mastodon-streaming-api-listener
Composer 安装命令:
composer require keinos/mastodon-streaming-api-listener
包简介
Listens to the server-sent messages of Mastodon Streaming API and returns the events in JSON.
README 文档
README
Simple Mastodon Streaming API Listener
This is a PHP class that listens to the Mastodon Streaming API's server-sent messages.
Install
composer require keinos/mastodon-streaming-api-listener
Usage
<?php require_once __DIR__ . '/../vendor/autoload.php'; $conf = [ // 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)); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; // Alias \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)); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use KEINOS\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)); }
Package Information
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-25