GithubHelp home page GithubHelp logo

edceza / twitterjsclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boycook/twitterjsclient

0.0 2.0 0.0 922 KB

Twitter client written in JavaScript packaged as a node module

License: GNU General Public License v2.0

Makefile 4.29% JavaScript 95.71%

twitterjsclient's Introduction

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-node-client
var Twitter = require('twitter-node-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-node-client').Twitter;

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

	// make a directory in the root folder of your project called data
	// copy the node_modules/twitter-node-client/twitter_config file over into data/twitter_config`
	// Open `data/twitter_config` and supply your applications `consumerKey`, 'consumerSecret', 'accessToken', 'accessTokenSecret', 'callBackUrl' to the appropriate fields in your data/twitter_config file
    
    var twitter = new Twitter();
	
	//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

twitterjsclient's People

Contributors

boycook avatar rakannimer avatar flozz avatar digicyc avatar btngo avatar m0llysour avatar porterk avatar paullebedev avatar filoozom avatar giratikanon avatar wdalmut avatar

Watchers

James Cloos avatar @elazar 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.