- How do I connect to Twitter’s Filtered Stream API using this Laravel package?
- Use the package’s `TwitterStream` facade to initialize a stream with your OAuth 1.0a credentials. Call `filter()` with keywords or rules, then listen to events via Laravel’s queue system or event listeners. Example: `$stream = TwitterStream::filter(['keyword1', 'keyword2']);`. Ensure your Twitter API keys are configured in Laravel’s `.env` file.
- Does this package support Twitter API v2’s User Stream or only Filtered Stream?
- The package supports both **Filtered Stream** and **User Stream** endpoints under Twitter API v2. For User Stream, use `user()` instead of `filter()` in the stream initialization. Verify your Twitter Developer account has access to these endpoints, as some features may require approval.
- How do I handle rate limits or connection timeouts in production?
- The package doesn’t include built-in retry logic, so implement exponential backoff using Guzzle middleware or Laravel’s `retry` helper. For critical apps, pair it with a circuit breaker (e.g., Spatie’s package) to gracefully handle disconnections. Monitor rate limits via Twitter’s API status endpoint or log HTTP 429 responses.
- Can I store tweets in a database or do I need to process them in real-time?
- The package streams raw JSON data—you’ll need to parse and store tweets manually. Use Laravel’s queue system to offload processing (e.g., `ProcessTweetJob`) and store data in PostgreSQL (JSONB), MongoDB, or Elasticsearch. For replayability, log tweets to a queue like Redis before processing.
- Will this work with Laravel 10+ and PHP 8.2? What about older versions?
- Check the package’s `composer.json` for Laravel/PHP version support (likely targets Laravel 8+ and PHP 8.0+). If unsupported, fork the repo or use a compatibility layer like `laravel/framework` v8.80.0. For legacy apps, test thoroughly—Twitter’s API changes may break older Laravel versions.
- How do I filter tweets by language or specific user mentions?
- Use Twitter’s [stream rules](https://developer.twitter.com/en/docs/twitter-api/streaming-api) syntax in the `filter()` method. Example: `TwitterStream::filter(['track' => 'laravel', 'lang' => 'en'])` for English-language tweets. For user mentions, include `from:` or `to:` rules, but note these may require Twitter’s elevated access.
- Can I use this package with Laravel Horizon for scaling multiple streams?
- Yes. Deploy multiple Horizon workers, each handling a separate stream (e.g., `twitter-stream:process` job). Use Redis queues to distribute load and avoid resource contention. Monitor worker health with Horizon’s dashboard to detect stalled streams or rate limits.
- What’s the best way to test this package locally without hitting Twitter’s rate limits?
- Mock the Twitter API responses using Laravel’s HTTP testing helpers or a service like [Vespa](https://vespa.ai/) for API mocking. Test stream reconnection by simulating network drops with Guzzle’s `onRequest` middleware. For unit tests, verify event dispatching and queue job execution without hitting real endpoints.
- Are there alternatives if I need more features like tweet archiving or advanced analytics?
- For archiving, pair this package with [spatie/laravel-activitylog](https://spatie.be/docs/laravel-activitylog) or a dedicated database. For analytics, integrate with Elasticsearch (via `elasticsearch/elasticsearch`) or use Twitter’s Premium API if your use case requires deeper insights. Libraries like `abraham/twitteroauth` offer broader API support but lack Laravel-specific features.
- How do I ensure compliance with Twitter’s Developer Agreement when scraping or storing tweets?
- Review Twitter’s [Developer Agreement](https://developer.twitter.com/en/developer-terms/agreement-and-policy) to confirm your use case (e.g., no scraping, proper attribution). Avoid storing tweets indefinitely unless required by your app. Use Laravel’s `hashed` column for sensitive data and implement data retention policies. For legal certainty, consult Twitter’s support or a compliance expert.