technoweenie / twitter-node

Discontinued: check out nTwitter
https://github.com/AvianFlu/ntwitter
MIT License
446 stars 547 forks source link

twitter-node

Creates a streaming connection with twitter, and pushes any incoming statuses to a tweet event.

Installation

Depends on ntest.

Use NPM:

npm install twitter-node

Otherwise create a symlink in ~/.node_libraries

$ ln -s /path/to/twitter-node/lib/twitter-node ~/.node_libraries/twitter-node

Events

TwitterNode emits these events:

See the streaming API docs for examples of the limit and delete commands.

Usage

// twitter-node does not modify GLOBAL, that's so rude
var TwitterNode = require('twitter-node').TwitterNode
  , util         = require('util')

// you can pass args to create() or set them on the TwitterNode instance
var twit = new TwitterNode({
  user: 'username', 
  password: 'password',
  host: 'my_proxy.my_company.com',         // proxy server name or ip addr
  port: 8080,                              // proxy port!
  track: ['baseball', 'football'],         // sports!
  follow: [12345, 67890],                  // follow these random users
  locations: [-122.75, 36.8, -121.75, 37.8] // tweets in SF
});

// adds to the track array set above
twit.track('foosball');

// adds to the following array set above
twit.follow(2345);

// follow tweets from NYC
twit.location(-74, 40, -73, 41)

// http://apiwiki.twitter.com/Streaming-API-Documentation#QueryParameters
twit.params['count'] = 100;

// http://apiwiki.twitter.com/Streaming-API-Documentation#Methods
twit.action = 'sample'; // 'filter' is default

twit.headers['User-Agent'] = 'whatever';

// Make sure you listen for errors, otherwise
// they are thrown
twit.addListener('error', function(error) {
  console.log(error.message);
});

twit
  .addListener('tweet', function(tweet) {
    util.puts("@" + tweet.user.screen_name + ": " + tweet.text);
  })

  .addListener('limit', function(limit) {
    util.puts("LIMIT: " + util.inspect(limit));
  })

  .addListener('delete', function(del) {
    util.puts("DELETE: " + util.inspect(del));
  })

  .addListener('end', function(resp) {
    util.puts("wave goodbye... " + resp.statusCode);
  })

  .stream();

// We can also add things to track on-the-fly
twit.track('#nowplaying');
twit.follow(1234);

// This will reset the stream
twit.stream();

Pre-Launch Checklist

See http://apiwiki.twitter.com/Streaming-API-Documentation. Keep these points in mind when getting ready to use TwitterNode in production:

TODO

\m/

Note on Patches/Pull Requests

Copyright

Copyright (c) 2010 rick. See LICENSE for details.