LaravelPackages.net
Acme Inc.
Toggle sidebar
unniks/twitter-powertracker

A Laravel Package for Twitter Powertrack

55
0
1.0.1
About unniks/twitter-powertracker

unniks/twitter-powertracker is a Laravel package for a laravel package for twitter powertrack. It currently has 0 GitHub stars and 55 downloads on Packagist (latest version 1.0.1). Install it with composer require unniks/twitter-powertracker. Discover more Laravel packages by unniks or browse all Laravel packages to compare alternatives.

Last updated

Twitter Power Tracker

Twitter Power Tracker is the package for connecting and streaming data with twitter's enterprise streaming plans.

Installation

$ composer require unniks/twitter-powertracker

Don't forget to add service provider

unniks\TwitterPowertracker\PowerTrackerServiceProvider::class,

Twitter Power Tracker comes with facade. Add following lines in aliases

'TwitterPowertracker' => unniks\TwitterPowertracker\PowerTrackFacade::class,

Publish Vendor Files for configuration

$ php artisan vendor:publish --provider="unniks\TwitterPowertracker\PowerTrackerServiceProvider"

Usage

We need GNIP account before using with this feature. If you have GNIP username and password, add following variables in your .env file

TWITTER_GNIP_USERNAME=[email protected] <br>
TWITTER_GNIP_PASSWORD=xxxxx <br>
TWITTER_GNIP_URL=https://gnip-stream.twitter.com/stream/powertrack/accounts/{username}/publishers/twitter/{variable}.json <br>
TWITTER_GNIP_REPLAY_URL=https://gnip-stream.gnip.com/replay/powertrack/accounts/{username}/publishers/twitter/{variabale}.json <br>
TWITTER_GNIP_STREAMING_30_DAYS_URL=https://gnip-api.twitter.com/search/30day/accounts/{username}/{variabale}.json <br>
TWITTER_GNIP_RULES_URL=https://gnip-api.twitter.com/rules/powertrack/accounts/{username}/publishers/twitter/{variabale}.json 

Use this facade

use TwitterPowertracker; 

For Rule Creation

if you can pass json format recomended by GNIP console

_

 $json =  {"rules" :[{"value" : "from:foo","tag" : "some_foo_tag"},{"value" : "foo:keyword"}]} ;
TwitterPowertracker::ruleCreationByJson($json);
or just pass array of rules like this using ruleCreationByArray()

_

$rules =['from:rahul','@shami'];
TwitterPowertracker::ruleCreationByArray($rules); 
if you need to pass tags as array just use like this

_

$rules = ['from:rahul','@shami'];
$tags = ['rahul_tag','sham_tag'];
TwitterPowertracker::ruleCreationByArray($rules,$tags);

note: array index of $tags should have matched to array index of $rules

For Rule Deletion

you can use above mentioned same techniques for

_

TwitterPowertracker::ruleDeletionByJson($json); 
and

_

TwitterPowertracker::ruleDeletionByJson($json); 
TwitterPowertracker::ruleDeletionByArray($rules,$tags); 

What is rules? Please go through this documentation: https://developer.twitter.com/en/docs/tweets/filter-realtime/overview/powertrack-api

For streaming data

use TwitterPowertracker; 
TwitterPowertracker::powerStream();

By calling powerStream() data will be continuously streamed to the model app/TwitterPowerTrackerStream.php

public static function getPowerTrack($data)
{
    //do some stuff with incoming $data
}

For force stopping the live streaming

//return "exit" in the function "app/TwitterPowerTrackerStream.php"

public static function getPowerTrack($data)
{
    //some code
    if(//some condition)
    {
      return "exit";
    }
}

For 30 days twitter data

Method 1
$results = TwitterPowertracker::thirtyDaysGet($rule);
Method 2
$results = TwitterPowertracker::thirtyDaysGet($rule,$maxResults);
Method 3
$results = TwitterPowertracker::thirtyDaysGet($rule,$maxResults,$startDate,$endDate);
Method 4
$results = TwitterPowertracker::thirtyDaysGet($rule,$maxResults,$startDate,$endDate,$next);

(use https://support.gnip.com/apis/search_api2.0/api_reference.html for reference)

********* Awaiting Brilliant Contributions for this simple Package **********

License

The unniks/twitter-powertracker is open-sourced software licensed under the [MIT license]

Comments