PHP code example of mineur / twitter-stream-api-bundle

1. Go to this page and download the library: Download mineur/twitter-stream-api-bundle 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/ */

    

mineur / twitter-stream-api-bundle example snippets


composer 

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Mineur\TwitterStreamApiBundle\TwitterStreamApiBundle(),
        ];
    }
}

// Controllers/DemoController.php

class DemoCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        //...
    }
    
    public function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var PublicStream $publicStream */
        $publicStream = $this
            ->getContainer()
            ->get('twitter_stream_api_consumer');
        $publicStream
            ->listenFor([
                'your', 
                'keywords', 
                'list'
            ])
            ->setLanguage('es')
            ->do(function(Tweet $tweet) {
                // you can do whatever you want with this output
                // prompt it, enqueue it, persist it into a database ...
                $output->writeln($tweet);
            });
    }
}

bin/console mineur:twitter-stream:consume hello,hola,aloha

bin/console mineur:twitter-stream:enqueue

Mineur\TwitterStreamApi\Tweet {#424
  -text: "Hello twitter!"
  -lang: "en"
  -createdAt: "Thu May 25 18:48:05 +0000 2017"
  -timestampMs: "1495738085984"
  -geo: array:12 [
    // ...
  ]
  -coordinates: array:14 [
    // ...
  ]
  -places: null
  -retweetCount: 236
  -favoriteCount: 52
  -user: array:38 [
    "id" => 2605080321
    // ...
  ]
}