This repository has been archived by the owner. It is now read-only.
[DEPRECATED] A node.js module for interacting with the Twitter API.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
examples
lib
tests
.gitignore
Makefile
README.md
package.json

README.md

Deprecation Notice


This project has been deprecated. The repo will remain available for the forseeable future but there will be no further activity.

Why?

node-twitter was birthed several years ago at a time when there were very few options for talking to twitter via nodejs. Our team was young, we were moving quickly and node-twitter was the result. Fast forward to today, we're a little older and much wiser. We could rewrite node-twitter but there are many options available that have solid tests and generally follow current nodejs programming paradigms. Because of this, we've decided to deprecate this project. We've decided to use twitter in it's place. Thanks to everyone who has supported the project!

If you have any questions please contact us at dev@isl.co

Description

node-twitter is a node.js module for interacting with the Twitter API.

Examples

REST

The Twitter REST API can be accessed using Twitter.RestClient. The following code example shows how to retrieve tweets from the authenticated user's timeline.

var Twitter = require('node-twitter');

var twitterRestClient = new Twitter.RestClient(
    'CONSUMER_KEY',
    'CONSUMER_SECRET',
    'TOKEN',
    'TOKEN_SECRET'
);

twitterRestClient.statusesHomeTimeline({}, function(error, result) {
    if (error)
    {
        console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
    }

    if (result)
    {
        console.log(result);
    }
});

Search

The Twitter Search API can be accessed using Twitter.SearchClient. The following code example shows how to search for tweets containing the keyword "node.js".

var Twitter = require('node-twitter');

var twitterSearchClient = new Twitter.SearchClient(
    'CONSUMER_KEY',
    'CONSUMER_SECRET',
    'TOKEN',
    'TOKEN_SECRET'
);

twitterSearchClient.search({'q': 'node.js'}, function(error, result) {
    if (error)
    {
        console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
    }

    if (result)
    {
        console.log(result);
    }
});

Streaming

The Twitter Streaming API can be accessed using Twitter.StreamClient. The following code example shows how to catch all tweets containing the keywords "baseball", "basketball", "football" or "hockey".

var Twitter = require('node-twitter');

var twitterStreamClient = new Twitter.StreamClient(
    'CONSUMER_KEY',
    'CONSUMER_SECRET',
    'TOKEN',
    'TOKEN_SECRET'
);

twitterStreamClient.on('close', function() {
    console.log('Connection closed.');
});
twitterStreamClient.on('end', function() {
    console.log('End of Line.');
});
twitterStreamClient.on('error', function(error) {
    console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
});
twitterStreamClient.on('tweet', function(tweet) {
    console.log(tweet);
});

twitterStreamClient.start(['baseball', 'basketball', 'football', 'hockey']);

Upload

Tweets with attached image media (JPG, PNG or GIF) can be posted using the upload API endpoint.

var Twitter = require('node-twitter');

var twitterRestClient = new Twitter.RestClient(
    'CONSUMER_KEY',
    'CONSUMER_SECRET',
    'TOKEN',
    'TOKEN_SECRET'
);

twitterRestClient.statusesUpdateWithMedia(
    {
        'status': 'Posting a tweet w/ attached media.',
        'media[]': '/some/absolute/file/path.jpg'
    },
    function(error, result) {
        if (error)
        {
            console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
        }

        if (result)
        {
            console.log(result);
        }
    };
);

License

node-twitter is made available under terms of the BSD 3-Clause License.

Unit Tests

To run the unit tests, open tests/UnitTestMain.js in a text editor and replace the OAuth placeholder values with your OAuth credentials.

Save the file then, from the command line, run:

make test

Contributing

Before submitting pull requests, please ensure your code is documented and there are unit tests for any new functionality.