Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Twitter Streaming Api

Laravel Twitter Streaming Api Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Easily work with the Twitter Streaming API in a Laravel app

Frequently asked questions about Laravel Twitter Streaming Api
How do I start streaming tweets for a specific hashtag in Laravel?
Use the `publicStream()` method with `whenHears()` to filter tweets. For example, `TwitterStreamingApi::publicStream()->whenHears('#laravel', function($tweet) { ... })->startListening()`. This triggers a closure whenever a matching tweet arrives. For production, wrap this in an Artisan command or queue job.
Does this package support user-specific streams (e.g., tracking a single account’s activity)?
Yes, use `userStream()` instead of `publicStream()` and pass the user’s Twitter credentials. This streams tweets, likes, follows, and other actions from a specific account. Ensure your Twitter API keys have the required permissions (e.g., `read:write` for user streams).
How do I handle rate limits or connection drops in a long-running stream?
The package automatically retries failed connections and respects Twitter’s rate limits. For critical applications, integrate Laravel queues (e.g., `listenForHashTags` dispatches jobs) and monitor stream health with Laravel Scout or Prometheus. Configure retry logic in the `config/laravel-twitter-streaming-api.php` file.
Can I process tweets asynchronously (e.g., using Laravel queues) instead of real-time?
Absolutely. Dispatch queue jobs inside the `whenHears()` closure, like `dispatch(new ProcessTweet($tweet))`. This decouples stream processing from the main application, improving scalability. Use Laravel Horizon to monitor worker performance and backpressure.
What Laravel versions are supported, and are there breaking changes between v8 and v10?
The package is tested on Laravel 8+ and supports up to Laravel 10. No major breaking changes exist between versions, but ensure your codebase uses compatible features (e.g., enums in Laravel 8+). Always check the [release notes](https://github.com/spatie/laravel-twitter-streaming-api/releases) for version-specific updates.
How do I store processed tweets in a database (e.g., Eloquent) without blocking the stream?
Offload storage to queue jobs or background workers. For example, in the `whenHears()` closure, dispatch a job to save the tweet to Eloquent: `Tweet::create($tweetData)`. Use Laravel’s queue system to avoid blocking the stream. For high-volume streams, consider batch inserts or a dedicated storage service.
Are there alternatives to this package for Laravel Twitter streaming?
Yes, alternatives include raw Guzzle HTTP requests to Twitter’s API or packages like `abraham/twitteroauth`. However, this package abstracts OAuth, rate limits, and reconnections, saving development time. For advanced use cases (e.g., multi-account streaming), evaluate whether the package’s modularity meets your needs before switching.
How do I test the package locally without hitting Twitter’s API limits?
Use Twitter’s sandbox environment or mock the `TwitterStreamingApi` facade in tests. For example, stub the `publicStream()` method to return a fake stream with predefined tweets. The package’s unit tests demonstrate this pattern. Avoid testing with real credentials in CI pipelines.
Can I filter or transform tweets before they’re processed (e.g., remove retweets)?
Yes, use middleware-like callbacks with `whenHears()` or chain methods like `filter()` to pre-process tweets. For example, `publicStream()->filter(function($tweet) { return !str_starts_with($tweet['text'], 'RT'); })->whenHears(...)` removes retweets. Custom middleware can be added via the package’s extension points.
What are the GDPR/privacy implications of storing tweet data, and how can I comply?
Tweets may contain personal data (e.g., usernames, locations). Implement data anonymization (e.g., hashing usernames) and retention policies (e.g., auto-delete after 30 days). Use Laravel’s encryption for sensitive fields and document your data processing in a privacy policy. Consider using Laravel’s `SoftDeletes` for compliance-friendly archival.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport