twit-stream

0.1.1 • Public • Published

twit-stream NPM version Build Status Dependency Status

A simplification for reading Twitter data using Node.JS Streams. Pass in OAuth info and select Twitter stream method, and get a Node stream2 returned. Choose whether you want a stream of objects (objectMode: true) or a stream of buffers.

Usage and Installation

npm install --save twitter-stream
 
var Twitter = require('twit-stream');
 
var options = {
  consumer_key: '',
  consumer_secret: '',
  oauth_token: '',
  oauth_secret: ''
};
 
var stream = new Twitter(options).filter({ track: 'Javascript' });
 
stream.pipe(objectHandler);
// Where objectHandler is an arbitrary write stream

See more examples

Stream Endpoints

See information about the different end points on the Twitter Developer site

API

new Twitter(options)

Parameter: option is object of options.
Returns: Twitter instance

Options must contain OAuth info

{
  "consumer_key": "",
  "consumer_secret": "",
  "oauth_token": "",
  "oauth_secret": ""
}

In addition to OAuth data, options allow you to define if the returned streams should be in objectMode or not.

options.objectMode

Type: Boolean
Default: true

With object mode the data passed is a stream of Twitter objects. By setting the objectMode to false, the streamed data is a stream of buffered strings, one tweet buffered up at the time.

objectMode: false could be used to pipe twitter data directly to file or to any other write stream requiering buffers.

.filter(data)

Parameter: data is request payload values (POST body) as documented by Twitter dev site.
Returns: Stream (with objectMode: true)

.sample(params)

Parameter: params is values as documented by Twitter dev site
Returns: Stream (with objectMode: true)

.firehose(params)

Parameter: params is values as documented by Twitter dev site
Returns: Stream (with objectMode: true)

Note: You need special premissions by Twitter to have access to the firehose endpoint.

Examples

options.objectMode = false;
new Twitter(options).sample()
  // pipe to file
  .pipe(fs.createWriteStream(__dirname + '/sample.dat'));

License

MIT License

Package Sidebar

Install

npm i twit-stream

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • mikaelb