Giter VIP home page Giter VIP logo

node-twitter's Introduction

Twitter API client library for node.js

node-twitter aims to provide a complete, asynchronous client library for the Twitter API, including the REST, search and streaming endpoints. It was inspired by, and uses some code from, @technoweenie's twitter-node.

Requirements

You can install node-twitter and its dependencies with npm: npm install twitter.

Getting started

It's early days for node-twitter, so I'm going to assume a fair amount of knowledge for the moment. Better documentation to come as we head towards a stable release.

Setup API (stable)

var util = require('util'),
	twitter = require('twitter');
var twit = new twitter({
	consumer_key: 'STATE YOUR NAME',
	consumer_secret: 'STATE YOUR NAME',
	access_token_key: 'STATE YOUR NAME',
	access_token_secret: 'STATE YOUR NAME'
});

Authenticate

The format of this depends somewhat on how your routing works, but it should be clear enough.

app.get('/', twit.gatekeeper('/login'), routes.index);
app.get('/login', routes.login);
app.get('/twauth', twit.login());

You'll need to create the routes for index & login. On the login page, you'll want a link like:

<a href="/twauth">Log in with Twitter</a>

Basic OAuth-enticated GET/POST API (stable)

The convenience APIs aren't finished, but you can get started with the basics:

twit.get('/statuses/show/27593302936.json', {include_entities:true}, function(data) {
	console.log(util.inspect(data));
});

REST API (unstable, may change)

Note that all functions may be chained:

twit
	.verifyCredentials(function(data) {
		console.log(util.inspect(data));
	})
	.updateStatus('Test tweet from node-twitter/' + twitter.VERSION,
		function(data) {
			console.log(util.inspect(data));
		}
	);

Search API (unstable, may change)

twit.search('nodejs OR #node', function(data) {
	console.log(util.inspect(data));
});

Streaming API (stable)

The stream() callback receives a Stream-like EventEmitter:

twit.stream('statuses/sample', function(stream) {
	stream.on('data', function(data) {
		console.log(util.inspect(data));
	});
});

node-twitter also supports user, filter and site streams:

twit.stream('user', {track:'nodejs'}, function(stream) {
	stream.on('data', function(data) {
		console.log(util.inspect(data));
	});
	// Disconnect stream after five seconds
	setTimeout(stream.destroy, 5000);
});

new added events

this library now supports new added events which you can listen on.

follow favorite unfavorite block unblock list_created list_destroyed list_updated list_member_added list_member_removed list_user_subscribed list_user_unsubscribed user_update

node-twitter's People

Contributors

alaaattya avatar christopherwright avatar chrisweb avatar desmondmorris avatar francois2metz avatar gnomus avatar haruair avatar hughrawlinson avatar hyl avatar iclems avatar jdub avatar jmalonzo avatar mulderp avatar oesmith avatar ptmt avatar qix- avatar romaintb avatar ryantenney avatar secos avatar technoweenie avatar tim-smart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.