spatie/laravel-twitter-streaming-api
Laravel package to consume Twitter’s Streaming API. Easily listen to public streams for keywords/hashtags or user actions with a fluent API and callbacks, then start a long-running listener (e.g., via an Artisan command) to process incoming tweets in real time.
listenForHashTags dispatches jobs to tweet-processor queue).TweetHeard) for decoupled consumers (e.g., notifications, analytics).php artisan twitter:stream --tags=#laravel).composer require spatie/laravel-twitter-streaming-api.publicStream()->whenHears()) in a local Laravel app.php artisan queue:work --daemon)..env.read:write for user streams)..env:
TWITTER_CONSUMER_KEY=...
TWITTER_CONSUMER_SECRET=...
TWITTER_ACCESS_TOKEN=...
TWITTER_ACCESS_TOKEN_SECRET=...
php artisan vendor:publish --provider="Spatie\TwitterStreamingApi\TwitterStreamingApiServiceProvider".TweetService to process raw tweets (e.g., store in DB, trigger events).* * * * * cd /path && php artisan twitter:stream >> /dev/null 2>&1).{
"level": "info",
"message": "Stream started for #laravel",
"context": { "stream_type": "filtered", "tags": ["#laravel"] }
}
config/twitter.php).php artisan twitter:stream --debug (if supported).| Failure | Impact | Mitigation |
|---|---|---|
| Twitter API downtime | No tweets processed | Implement fallback (e.g., cache last N tweets). |
| Rate limit exceeded | Stream pauses | Use exponential backoff; switch to user streams. |
| Queue worker crash | Unprocessed tweets | Supervisor/PM2 to auto-restart workers. |
| Database connection loss | Processing delays | Queue retries with dead-letter queue. |
| Malformed tweet data | Processing errors | Schema validation; log and skip. |
TweetProcessor class.How can I help you explore Laravel packages today?