dev-master
9999999-devCollector of streaming twitter data
MIT
The Requires
The Development Requires
- phpunit/phpunit ^6.1
- symfony/var-dumper ^3.2
- mockery/mockery ^0.9.9
- fzaninotto/faker ^1.6
- mmoreram/php-formatter ^1.3
by Alex Casajuana
Wallogit.com
2017 © Pedro Peláez
Collector of streaming twitter data
Another Twitter Stream PHP library. For now it just works on public stream, using the filter method., (*2)
composer require mineur/twitter-stream-api:dev-master
Instantiate the GuzzleHttpClient adapter with your Twitter api tokens. And start consuming Twitter's Stream with some keywords! :) \ If you don't have your Twitter API credentials, check this: How to get your twitter access tokens , (*3)
use Mineur\TwitterStreamApi\Http\GuzzleStreamClient;
use Mineur\TwitterStreamApi\PublicStream;
$streamClient = new GuzzleStreamClient(
'consumer_key',
'consumer_secret',
'access_token',
'access_token_secret'
);
PublicStream::open($streamClient)
->listenFor([
'your',
'keywords',
'list'
])
->consume();
Working with the Twitter Stream you cannot open two stream lines with the same account. You should create another app account and raise a new instance of this library., (*4)
You can also use a callback instead, if you want to modify the original output:, (*5)
use Mineur\TwitterStreamApi\Tweet;
PublicStream::open($streamClient)
->listenFor([
'your',
'keywords',
'list'
])
->do(function(Tweet $tweet) {
echo "$tweet->getUser() tweeted: $tweet->getText()";
});
In this example you'll only get the tweets of a user corresponding to its ID., (*6)
$myTwitterId = '1234567';
PublicStream::open($streamClient)
->tweetedBy([
$myTwitterId
])
->consume();
In this example you'll only get the tweets on your keywords list write in spanish language., (*7)
PublicStream::open($streamClient)
->listenFor([
'keywords',
'list'
])
->setLanguage('es')
->consume();
Once you receive the output from the PublicStream, let's say when you are using the do
callback function, the output will always be an hydrated Tweet value object.
\
You can access it with the following methods:
* Using getters:, (*8)
// Get specific data from the object $tweet->getText();
// Transform object to an array, then access to the data $aTweet = $tweet->toArray(); $aTweet['text'];
// A complete serialized object to enqueue it, for example $tweet->serialized();
For Symfony integrations you can refer to this bundle: Mineur Twitter Stream Api Bundle, (*9)
composer install ./bin/phpunit
To check the coverage just add:, (*10)
./bin/phpunit --coverage-text
filter_level featurelocation featureCollector of streaming twitter data
MIT