npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twitter-node-client

v0.0.6

Published

Twitter JS Client

Downloads

356

Readme

Build Status Coverage Status Dependency Status NPM

Description

A Twitter Node Module to authenticate and interact with the Twitter REST API from NodeJS.

Installation

npm install twitter-js-client
var Twitter = require('twitter-js-client').Twitter;

Usage

You need to create a Twitter app to use the API.

	//Callback functions
	var error = function (err, response, body) {
    	console.log('ERROR [%s]', err);
	};
	var success = function (data) {
    	console.log('Data [%s]', data);
	};

	var Twitter = require('twitter-js-client').Twitter;

	//Get this data from your twitter apps dashboard
	var config = {
    	"consumerKey": "XXX",
    	"consumerSecret": "XXX",
    	"accessToken": "XXX",
    	"accessTokenSecret": "XXX",
    	"callBackUrl": "XXX"
	}

    var twitter = new Twitter(config);
	
	//Example calls

	twitter.getUserTimeline({ screen_name: 'BoyCook', count: '10'}, error, success);
	
	twitter.getMentionsTimeline({ count: '10'}, error, success);
	
	twitter.getHomeTimeline({ count: '10'}, error, success);
	
	twitter.getReTweetsOfMe({ count: '10'}, error, success);
	
	twitter.getTweet({ id: '1111111111'}, error, success);

	
	//
	// Get 10 tweets containing the hashtag haiku
	//

	twitter.getSearch({'q':'#haiku','count': 10}, error, success);
	
	//
	// Get 10 popular tweets with a positive attitude about a movie that is not scary 
	//

	twitter.getSearch({'q':' movie -scary :) since:2013-12-27', 'count': 10, 'result\_type':'popular'}, error, success);

Twitter has a comprehensive REST api if you need to use something that doesn't have a wrapper function in the library call it directly :

	twitter.getCustomApiCall('/statuses/lookup.json',{ id: '412312323'}, error, success);
	twitter.postCustomApiCall('/direct_messages/new.json',{user_id: '1234', 'text':'This is easy.'}, error, success);

To get the list of expected parameters and results, check https://dev.twitter.com/rest/public

Functions

Search Tweets. Docs

To learn how to use Twitter Search effectively read Using the Twitter Search API

	twitter.getSearch(parameters, errorCallback, successCallback);

 

Update user's status (Tweet). Docs
	twitter.postTweet(parameters, errorCallback, successCallback);

 

Follow another user by user_id or screen_name(handle). Docs
	twitter.postCreateFriendship(parameters, errorCallback, successCallback);

 

Get a user's timelineDocs
	twitter.getUserTimeline(parameters, errorCallback, successCallback);

 

Get the latest 20 recent mentions for the authenticating user. Docs
	twitter.getMentionsTimeline(parameters, errorCallback, successCallback);

 

Get the latest tweets and retweets by the authenticating users and the ones they follow. Docs
	twitter.getHomeTimeline(parameters, errorCallback, successCallback);

 

Get latest retweets of authenticated user. Docs
	twitter.getReTweetsOfMe(parameters, errorCallback, successCallback);

 

Get a tweet by id. Docs
	twitter.getTweet(parameters, errorCallback, successCallback);

 

Get information about a user by user_id or handle (screen_name). Docs
	twitter.getUser(parameters, errorCallback, successCallback);

 

Get a cursored collection of the followers of a user_id or a handle (screen_name). Docs
	twitter.getFollowersList(parameters, errorCallback, successCallback);

 

Get a cursored collection of the followers' ids of a user_id or a handle (screen_name). Docs
	twitter.getFollowersIds(parameters, errorCallback, successCallbackok);

 

Upload media (images) to Twitter. Docs
	twitter.postMedia(parameters, errorCallback, successCallback);

Tests

There is a test file TwitterITSpec.js that does a basic integration tests of the client. It uses a properties file test/spec/properties.json to inject in the OAuth properties. These will need to be updated with your own details before the tests will run

Running tests

make test