2017 © Pedro Peláez
 

php-library twitter-stream-api

Collector of streaming twitter data

image

mineur/twitter-stream-api

Collector of streaming twitter data

  • Sunday, July 16, 2017
  • by alexhoma
  • Repository
  • 1 Watchers
  • 8 Stars
  • 51 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Twitter Streaming API

License Build Status Code Climate Latest Unstable Version Total Downloads, (*1)

Another Twitter Stream PHP library. For now it just works on public stream, using the filter method., (*2)

Index

Installation

composer require mineur/twitter-stream-api:dev-master

Basic initialization

Instantiate the GuzzleHttpClient adapter with your Twitter api tokens. And start consuming Twitter's Stream with some keywords! :) \ If you don't have your Twitter API credentials, check this: How to get your twitter access tokens , (*3)

use Mineur\TwitterStreamApi\Http\GuzzleStreamClient;
use Mineur\TwitterStreamApi\PublicStream;

$streamClient = new GuzzleStreamClient(
    'consumer_key',
    'consumer_secret',
    'access_token',
    'access_token_secret'
);
PublicStream::open($streamClient)
    ->listenFor([
        'your',
        'keywords',
        'list'
    ])
    ->consume();

Working with the Twitter Stream you cannot open two stream lines with the same account. You should create another app account and raise a new instance of this library., (*4)

Callback method

You can also use a callback instead, if you want to modify the original output:, (*5)

use Mineur\TwitterStreamApi\Tweet;

PublicStream::open($streamClient)
    ->listenFor([
        'your',
        'keywords',
        'list'
    ])
    ->do(function(Tweet $tweet) {
        echo "$tweet->getUser() tweeted: $tweet->getText()";
    });

Filtering tweets by user ID

In this example you'll only get the tweets of a user corresponding to its ID., (*6)

$myTwitterId = '1234567';
PublicStream::open($streamClient)
    ->tweetedBy([
        $myTwitterId
    ])
    ->consume();

Filtering keywords by language

In this example you'll only get the tweets on your keywords list write in spanish language., (*7)

PublicStream::open($streamClient)
    ->listenFor([
        'keywords',
        'list'
    ])
    ->setLanguage('es')
    ->consume();

The Tweet object

Once you receive the output from the PublicStream, let's say when you are using the do callback function, the output will always be an hydrated Tweet value object. \ You can access it with the following methods: * Using getters:, (*8)

// Get specific data from the object
$tweet->getText();
  • As an array:
// Transform object to an array, then access to the data
$aTweet = $tweet->toArray();
$aTweet['text'];
  • Serialized:
// A complete serialized object to enqueue it, for example
$tweet->serialized();

Integrations

For Symfony integrations you can refer to this bundle: Mineur Twitter Stream Api Bundle, (*9)

Run tests

composer install
./bin/phpunit

To check the coverage just add:, (*10)

./bin/phpunit --coverage-text

Todo's

  • STREAMING_ENDPOINT should be changed by client, using simple string injection
  • Add links of the filters in documentation
  • Test the first version of this library using Unit testing
  • Handle when a user removes a tweet on the fly.
  • Add filter_level feature
  • Add track location feature

The Versions

16/07 2017

dev-master

9999999-dev

Collector of streaming twitter data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alex Casajuana