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
Twitter Stream Api

Twitter Stream Api Laravel Package

redwebcreation/twitter-stream-api

Laravel-friendly PHP wrapper for Twitter’s Streaming API. Authenticate with OAuth and open filtered streams to receive tweets/events in real time, with simple configuration and callbacks for handling incoming data—ideal for building live feeds, monitors, and bots.

View on GitHub
Deep Wiki
Context7

Consume the Twitter Stream API in real-time.

Frequently asked questions about Twitter Stream Api
How do I set up OAuth credentials for Twitter’s API in this Laravel package?
The package abstracts OAuth 1.0a authentication. Configure your Twitter API keys and secrets in Laravel’s `.env` file (e.g., `TWITTER_CONSUMER_KEY`, `TWITTER_CONSUMER_SECRET`), then pass them to the package’s stream client. No manual OAuth flow is needed—it handles token requests automatically for Filtered or User Streams.
Can I use this package to track specific keywords or hashtags in real-time?
Yes, the package supports Twitter’s Filtered Stream API, which lets you specify keywords, hashtags, or user IDs. Pass an array of tracking rules (e.g., `['#laravel', 'php']`) to the stream client’s `filter()` method to start a live feed matching those terms.
What Laravel versions does this package support, and how do I install it?
The package targets Laravel 8.x and 9.x (PHP 8.0+). Install via Composer: `composer require redwebcreation/twitter-stream-api`. No additional Laravel service providers are needed—just configure your Twitter credentials and start streaming in a controller or job.
How do I handle incoming tweets or events from the stream in my Laravel app?
Use the package’s `onTweet()` or `onEvent()` callback methods to process raw JSON data. For example, bind a closure to `onTweet(fn($tweet) => Log::info($tweet['text']))` to log tweets. For complex logic, dispatch Laravel events or queue jobs (e.g., `ProcessTweetJob::dispatch($tweet)`).
Does this package support Twitter API v2’s new endpoints like the Academic Research API?
No, this package only supports Twitter API v1.1’s Filtered Stream and User Stream endpoints. For v2 features (e.g., Academic Research API or Premium endpoints), you’ll need a separate library like `abraham/twitteroauth` or Twitter’s official v2 SDK, as the APIs use different auth and response formats.
How do I handle rate limits or connection drops in a production stream?
Twitter’s API enforces rate limits (e.g., 500–1,500 requests/15 minutes for streams). The package doesn’t include retry logic, so implement exponential backoff using Guzzle middleware or Laravel’s `retry` helper. For connection drops, wrap the stream in a loop with error handling (e.g., `try-catch` blocks) or use a circuit breaker like Spatie’s package.
Can I store tweets in a database or Elasticsearch using this package?
The package returns raw tweet JSON, so you’ll need to parse and normalize it before storage. For databases, use Laravel’s Eloquent or a JSONB column (PostgreSQL). For Elasticsearch, pipe tweets to a queue and process them with a job that indexes data via `elasticsearch/elasticsearch`. Consider deduplicating retweets or likes to avoid data bloat.
Is this package suitable for high-volume streams (e.g., thousands of tweets per minute)?
For high-volume streams, offload processing to Laravel queues (e.g., Redis or database queues) and use Horizon for worker scaling. Avoid blocking HTTP requests—start the stream in a long-running job or daemon (e.g., Laravel Forge supervisor). Monitor memory usage, as raw tweet processing can be resource-intensive.
What are the alternatives to this package for Laravel Twitter streaming?
Alternatives include `abraham/twitteroauth` (low-level, requires manual stream handling) or Twitter’s official PHP SDK (`twitter/api-php`). For Laravel-specific solutions, consider `spatie/laravel-twitter` (limited to v1.1) or building a custom wrapper around Guzzle for v2. This package stands out for its Laravel integration and callback simplicity.
How do I test my Twitter stream in development without hitting rate limits?
Use Twitter’s sandbox environment (if available) or mock the stream responses in tests with Laravel’s HTTP client. For unit tests, inject a fake stream client (e.g., via dependency injection) and assert callback invocations. For integration tests, use a lightweight test database to store processed tweets and verify workflows without real API calls.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky