PHPackages                             carloscgo/laravel-twitter-streaming - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. carloscgo/laravel-twitter-streaming

ActiveLibrary[API Development](/categories/api)

carloscgo/laravel-twitter-streaming
===================================

Easily work with the Twitter Streaming API in a Laravel app

1.0.4(7y ago)18MITPHPPHP ^7.0

Since Aug 13Pushed 7y ago1 watchersCompare

[ Source](https://github.com/carloscgo/laravel-twitter-streaming)[ Packagist](https://packagist.org/packages/carloscgo/laravel-twitter-streaming)[ Docs](https://github.com/carloscgo/laravel-twitter-streaming)[ RSS](/packages/carloscgo-laravel-twitter-streaming/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (6)Used By (0)

Easily work with the Twitter Streaming API in a Laravel app
===========================================================

[](#easily-work-with-the-twitter-streaming-api-in-a-laravel-app)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a77129212054cc7b062c899a37bb56045890ef0892581bbf334a748391ad284e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361726c6f7363676f2f6c61726176656c2d747769747465722d73747265616d696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carloscgo/laravel-twitter-streaming)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e420f0d57a5820eb9b39d3c3858c001af566ff00f946dc96caea7de3a7d712f6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6361726c6f7363676f2f6c61726176656c2d747769747465722d73747265616d696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/carloscgo/laravel-twitter-streaming)[![Quality Score](https://camo.githubusercontent.com/288d3085cbd2b80868b440197a4efe16754431626d4822fc9956d1d7f2a54db7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6361726c6f7363676f2f6c61726176656c2d747769747465722d73747265616d696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/carloscgo/laravel-twitter-streaming)[![Total Downloads](https://camo.githubusercontent.com/f0e334776141be9fe429bf89daccb94d8d5cd29b084bfcafa67addd60006b7b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361726c6f7363676f2f6c61726176656c2d747769747465722d73747265616d696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/carloscgo/laravel-twitter-streaming)

Twitter provides a streaming API with which you can do interesting things such as listening for tweets that contain specific strings or actions a user might take (e.g. liking a tweet, following someone,...). This package makes it very easy to work with the API.

```
TwitterStreaming::publicStream($business_id)
->whenHears('#laravel', function(array $tweet) {
    echo "{$tweet['user']['screen_name']} tweeted {$tweet['text']}";
})
->startListening();
```

Here's [an example Laravel application](https://github.com/spatie/laravel-twitter-streaming-api-example-app) with the package pre-installed. It contains [an artisan command](https://github.com/spatie/laravel-twitter-streaming-api-example-app/blob/master/app/Console/Commands/ListenForHashTags.php) to kick off the listening process.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require carloscgo/laravel-twitter-streaming
```

You must install this service provider.

```
// config/app.php
'providers' => [
    ...
    CarlosCGO\LaravelTwitterStreaming\TwitterStreamingServiceProvider::class,
];
```

This package also comes with a facade, which provides an easy way to call the class.

```
// config/app.php
'aliases' => [
    ...
    'TwitterStreaming' => CarlosCGO\LaravelTwitterStreaming\TwitterStreamingFacade::class,
];
```

The config file must be published with this command:

```
php artisan vendor:publish --provider="CarlosCGO\LaravelTwitterStreaming\TwitterStreamingServiceProvider" --tag="config"
```

It will be published in `config/laravel-twitter-streaming.php`

```
return [

    /**
     * To work with Twitter's Streaming API you'll need some credentials.
     *
     * If you don't have credentials yet, head over to https://apps.twitter.com/
     */

    'table' => env('TWITTER_CONFIG_TABLE'),

    'where_field_business' => env('TWITTER_FIELD_BUSINESS'),

];
```

Getting credentials
-------------------

[](#getting-credentials)

In order to use this package you'll need to get some credentials from Twitter. Head over to the [Application management on Twitter](https://apps.twitter.com/) to create an application.

Once you've created your application, click on the `Keys and access tokens` tab to retrieve your `consumer_key`, `consumer_secret`, `access_token` and `access_token_secret`.

[![Keys and access tokens tab on Twitter](https://camo.githubusercontent.com/408bf9d0739c52a2688598f12a55a5d47f475faee383d1dfc47c38fa051db4bf/68747470733a2f2f6361726c6f7363676f2e6769746875622e696f2f747769747465722d73747265616d696e672f696d616765732f747769747465722e6a7067)](https://camo.githubusercontent.com/408bf9d0739c52a2688598f12a55a5d47f475faee383d1dfc47c38fa051db4bf/68747470733a2f2f6361726c6f7363676f2e6769746875622e696f2f747769747465722d73747265616d696e672f696d616765732f747769747465722e6a7067)

Usage
-----

[](#usage)

Currently, this package works with the public stream and the user stream. Both the `PublicStream` and `UserStream` classes provide a `startListening` function that kicks of the listening process. Unless you cancel it your PHP process will execute that function forever. No code after the function will be run.

In the example below a facade is used. If you don't like facades you can replace them with

```
app(CarlosCGO\LaravelTwitterStreaming\TwitterStreaming::class)
```

### The public stream

[](#the-public-stream)

The public stream can be used to listen for specific words that are being tweeted.

The first parameter of `whenHears` must be a string or an array containing the word or words you want to listen for. The second parameter should be a callable that will be executed when one of your words is used on Twitter.

```
use TwitterStreaming;

TwitterStreaming::publicStream($business_id)
->whenHears('#laravel', function(array $tweet) {
    echo "{$tweet['user']['screen_name']} tweeted {$tweet['text']}";
})
->startListening();
```

### The user stream

[](#the-user-stream)

```
use TwitterStreaming;

TwitterStreaming::userStream($business_id)
->onEvent(function(array $event) {
    if ($event['event'] === 'favorite') {
        echo "Our tweet {$event['target_object']['text']} got favorited by {$event['source']['screen_name']}";
    }
})
->startListening();
```

Suggestion on how to run in a production environment
----------------------------------------------------

[](#suggestion-on-how-to-run-in-a-production-environment)

When using this in production you could opt to create [an artisan command](https://github.com/spatie/laravel-twitter-streaming-api-example-app/blob/8175995/app/Console/Commands/ListenForHashTags.php) to listen for incoming events from Twitter. You can use [Supervisord](http://supervisord.org/) to make sure that command is running all the time.

A word to the wise
------------------

[](#a-word-to-the-wise)

These APIs work in realtime, so they could report a lot of activity. If you need to do some heavy work processing that activity it's best to put that work in a queue to keep your listening process fast.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

2876d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/693763?v=4)[Carlos G. Camacho O.](/maintainers/carloscgo)[@carloscgo](https://github.com/carloscgo)

---

Top Contributors

[![carloscgo](https://avatars.githubusercontent.com/u/693763?v=4)](https://github.com/carloscgo "carloscgo (6 commits)")

---

Tags

carloscgolaravel-twitter-streaming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/carloscgo-laravel-twitter-streaming/health.svg)

```
[![Health](https://phpackages.com/badges/carloscgo-laravel-twitter-streaming/health.svg)](https://phpackages.com/packages/carloscgo-laravel-twitter-streaming)
```

###  Alternatives

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[riclep/laravel-storyblok

A Laravel wrapper around the Storyblok API to provide a familiar experience for Laravel devs

6277.0k5](/packages/riclep-laravel-storyblok)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.1k1](/packages/jasara-php-amzn-selling-partner-api)[rapidez/core

Rapidez Core

1822.4k65](/packages/rapidez-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
