PHP code example of carloscgo / laravel-twitter-streaming

1. Go to this page and download the library: Download carloscgo/laravel-twitter-streaming library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

carloscgo / laravel-twitter-streaming example snippets


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

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

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

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'),

];

app(CarlosCGO\LaravelTwitterStreaming\TwitterStreaming::class)

use TwitterStreaming;

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

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();
bash
php artisan vendor:publish --provider="CarlosCGO\LaravelTwitterStreaming\TwitterStreamingServiceProvider" --tag="config"