owlycode / streaming-bird
Phirehose 启发的 Twitter 流式 API 的 PHP 客户端。
v0.1.1
2018-02-12 08:42 UTC
Requires
- php: ~5.6|~7.0
Requires (Dev)
- phpunit/phpunit: ~4.7
- symfony/process: ~3.0
This package is auto-updated.
Last update: 2024-09-08 03:38:53 UTC
README
StreamingBird 是一个自动测试、符合 PSR-4 规范的 Twitter 流式 API 客户端。
如何安装
使用 composer: composer require owlycode/streaming-bird
.
示例用法
use OwlyCode\StreamingBird\StreamReader; use OwlyCode\StreamingBird\StreamingBird; // Change these with yours. $oauthToken = 'my token'; $oauthSecret = 'secret'; $consumerKey = 'my key'; $consumerSecret = 'secret'; $bird = new StreamingBird($consumerKey, $consumerSecret, $oauthToken, $oauthSecret); $bird ->createStreamReader(StreamReader::METHOD_FILTER) ->setTrack(['hello', 'hola', 'bonjour']) // Fetch every tweet containing one of the following words ->consume(function ($tweet) { // Now we provide a callback to execute on every received tweet. echo '------------------------' . "\n"; echo $tweet['text'] . "\n"; }) ;
监控
StreamingBird 包含一些关于流的统计数据,您可以访问。目前这是一个早期尝试,信息有限,但预计未来会不断增长。
$reader->consume(function ($tweet, $monitor) use ($output) { echo '------------------------' . "\n"; echo $monitor->get('tweets') . "\n"; // The total number of received tweets echo $monitor->get('idle_time') . "\n"; // Elapsed seconds between the last two tweets. echo $monitor->get('max_idle_time') . "\n"; // The maximum idle time since the beginning. echo $tweet['text'] . "\n"; });
运行测试
简单地运行
composer install ./bin/vendor/phpunit