All Projects → spatie → Laravel Twitter Streaming Api

spatie / Laravel Twitter Streaming Api

Licence: mit
Easily work with the Twitter Streaming API in a Laravel app

Projects that are alternatives of or similar to Laravel Twitter Streaming Api

Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: ✭ 755 (+393.46%)
Mutual labels:  laravel, twitter, tweets
Api Response
Simple and ready to use API response wrapper for Laravel.
Stars: ✭ 123 (-19.61%)
Mutual labels:  api, laravel
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+1032.68%)
Mutual labels:  api, laravel
Real Time Sentiment Tracking On Twitter For Brand Improvement And Trend Recognition
A real-time interactive web app based on data pipelines using streaming Twitter data, automated sentiment analysis, and MySQL&PostgreSQL database (Deployed on Heroku)
Stars: ✭ 127 (-16.99%)
Mutual labels:  twitter, tweets
Deeply
PHP client for the DeepL.com translation API (unofficial)
Stars: ✭ 152 (-0.65%)
Mutual labels:  api, laravel
Laravel Hateoas
Expose the authorization logic of your REST API using HATEOAS links
Stars: ✭ 116 (-24.18%)
Mutual labels:  api, laravel
Remove Bg
Programmatically remove backgrounds from your images using the remove.bg api
Stars: ✭ 124 (-18.95%)
Mutual labels:  api, laravel
Totoval
An out-of-the-box artisan API web-framework written in go.
Stars: ✭ 110 (-28.1%)
Mutual labels:  api, laravel
Laravel Api Explorer
API explorer for laravel applications
Stars: ✭ 138 (-9.8%)
Mutual labels:  api, laravel
Laravel Fractal
An easy to use Fractal wrapper built for Laravel and Lumen applications
Stars: ✭ 1,748 (+1042.48%)
Mutual labels:  api, laravel
Twitter Streaming Api
Easily work with the Twitter Streaming API
Stars: ✭ 139 (-9.15%)
Mutual labels:  api, twitter
Laravel Api Boilerplate
A Boilerplate Project For Laravel API's (NOT MAINTAINED)
Stars: ✭ 113 (-26.14%)
Mutual labels:  api, laravel
Overwatch Api
A RESTful API for the Overwatch Game
Stars: ✭ 112 (-26.8%)
Mutual labels:  api, laravel
L5 Swagger
OpenApi or Swagger integration to Laravel
Stars: ✭ 1,781 (+1064.05%)
Mutual labels:  api, laravel
Laqul
A complete starter kit that allows you create amazing apps that look native thanks to the Quasar Framework. Powered by an API developed in Laravel Framework using the easy GraphQL queries language. And ready to use the Google Firebase features.
Stars: ✭ 110 (-28.1%)
Mutual labels:  api, laravel
Laravel Hackathon Starter
💻 A hackathon/MVP boilerplate for laravel web applications. Start your hackathons without hassle.
Stars: ✭ 1,589 (+938.56%)
Mutual labels:  api, laravel
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-1.96%)
Mutual labels:  api, laravel
Vue Api Query
💎 Elegant and simple way to build requests for REST API
Stars: ✭ 1,528 (+898.69%)
Mutual labels:  api, laravel
Twint
An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
Stars: ✭ 12,102 (+7809.8%)
Mutual labels:  twitter, tweets
Laravel cities
Find any country/city in the world. Get Long/Lat etc. Deploy geonames.org database localy. Optimized DB tree
Stars: ✭ 133 (-13.07%)
Mutual labels:  api, laravel

Easily work with the Twitter Streaming API in a Laravel app

Latest Version on Packagist Software License Test Status Total Downloads

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.

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

Here's an example Laravel application with the package pre-installed. It contains an artisan command to kick off the listening process.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-twitter-streaming-api

You must install this service provider.

// config/app.php
'providers' => [
    ...
    Spatie\LaravelTwitterStreamingApi\TwitterStreamingApiServiceProvider::class,
];

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

// config/app.php
'aliases' => [
    ...
    'TwitterStreamingApi' => Spatie\LaravelTwitterStreamingApi\TwitterStreamingApiFacade::class,
];

The config file must be published with this command:

php artisan vendor:publish --provider="Spatie\LaravelTwitterStreamingApi\TwitterStreamingApiServiceProvider" --tag="config"

It will be published in config/laravel-twitter-streaming-api.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/
     */

    'access_token' => env('TWITTER_ACCESS_TOKEN'),

    'access_token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET'),

    'consumer_key' => env('TWITTER_CONSUMER_KEY'),

    'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
];

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 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

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(Spatie\LaravelTwitterStreamingApi\TwitterStreamingApi::class)

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 TwitterStreamingApi;

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

The user stream

use TwitterStreamingApi;

TwitterStreamingApi::userStream()
->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

When using this in production you could opt to create an artisan command to listen for incoming events from Twitter. You can use Supervisord to make sure that command is running all the time.

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

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].