Package Data | |
---|---|
Maintainer Username: | rbadillap |
Maintainer Contact: | info@ronnybadilla.com (Ronny Badilla) |
Package Create Date: | 2016-01-03 |
Package Last Update: | 2016-01-05 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-22 03:04:44 |
Package Statistics | |
---|---|
Total Downloads: | 331 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
We are now supporting TwitterStreamingPHP with Laravel 5 through a Service Provider :)
This TwitterStreamingPHP Service Provider can be installed via Composer. Running the following command:
composer require rbadillap/twitterstreaming-laravel
Now you should register the provider in the Laravel application in your config/app.php
configuration file:
'providers' => [
// other service providers..
TwitterStreaming\Laravel\TwitterStreamingServiceProvider::class
],
Also, add the TwitterStreaming
facade in the aliasses
array (located in the same file).
'TwitterStreaming' => TwitterStreaming\Laravel\Facades\TwitterStreaming::class
Also you may want to create a twitterstreaming.php
configuration file, to do that and put on it the credentials of your Twitter App you should run the following command:
php artisan vendor:publish
Now, you can see a new file created in the app
folder where you can add your credentials.
And ready to use!
To understand how to use TwitterStreamingPHP please visit its documentation
Within this Service Package you will find some extra methods to simplify the way to work with TwitterStreamingPHP in Laravel. Let's take a look all of them:
Instead of define the endpoints using the endpoint
method in TwitterStreamingPHP you can call some methods which injects the endpoint (and its types) directly. For example:
// Instead of
(new Tracker)
->endpoint(Endpoints\PublicEndpoint::class, 'sample')
// You can call in Laravel
TwitterStreaming::publicSample()
// and continue with the rest of the code
All the methods to simplify the endpoints definitions listed here:
publicFilter()
// alias of endpoint(Endpoints\PublicEndpoint::class, 'filter')
publicSample()
// alias of endpoint(Endpoints\PublicEndpoint::class, 'sample')
user()
// alias of endpoint(Endpoints\UserEndpoint::class)
Are you using Filters module?
If no, well, you should :)
If yes, we have been integrated into the Laravel Service Provider.
The only thing that you need to use is require the package using composer:
composer require rbadillap/twitterstreaming-filters
And use it without the need to register the new extension.
// this is not necessary
->addExtension(Extensions\Filters::class)
// TwitterStreamingPHP detects automatically if the module are included with composer
// and you can use filters method automatically
->filters(function ($filters) {
return $filters
// Use methods to filter tweets
->withoutRTs()
->withoutReplies()
->onlyFromAndroid();
})
There is some ways, but if you wanna combine Laravel and TwitterStreamingPHP you can create your own command
php artisan make:console TwitterTrack
And put your logic to track tweets.
TwitterStreaming::publicFilter()
->parameters([
'track' => '#realmadrid'
])
->filters(function ($filters) {
return $filters
->withoutRTs()
->withoutReplies()
->onlyFromAndroid();
})
->track(function ($tweet) {
print $tweet->text . ' (' . $tweet->source . ')' . PHP_EOL . PHP_EOL;
});
Even better, you could dispatch a queue listener to store in database.
TwitterStreaming::publicFilter()
->parameters([
'track' => '#realmadrid'
])
->filters(function ($filters) {
return $filters
->withoutRTs()
->withoutReplies()
->onlyFromAndroid();
})
->track(function ($tweet) {
// php artisan make:job YourLaravelJob
$this->dispatch(new YourLaravelJob($tweet));
});
Use the same workflow as many of the packages that we have here in Github.