Socket
Book a DemoInstallSign in
Socket

twitter-request

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-request

Request to the Twitter API

0.5.5
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Twitter Request

Twitter-Request is a module to make easy authentificated request to the Twitter API. (Only user-authentification is supported for now)

How can i install it

npm install --save twitter-request

How can i use it

var TwitterRequest = require('TwitterRequest');

var oauth = {
	// Mandatory
	consumer_key: "CONSUMER_KEY",
	consumer_secret: "CONSUMER_SECRET",
	
	// Optional
	token: "USER_TOKEN",
	token_secret: "USER_SECRET_TOKEN"
};

var treq = new TwitterRequest(oauth);

// Go to https://dev.twitter.com/docs/api/1.1 to have endpoints documentation
treq.request('statuses/update', {
	// Add query to the url 
	query: {
		'status': 'Hello Twitter ! I will destroy this tweet in 5 seconds c:'
	}
}, function(err, res, body){
	// err => ERROR
	// res => ServerResponse
	// body => Body of the response

	if(err) throw err;

	if(res.statusCode !== 200)
		throw new Error('For some reason, Twitter reject the request D:\n\rMore information:\n\r' + JSON.parse(body));

	setTimeout(function(){
		treq.request('statuses/destroy', {
			// Replace url parameters (statuses/destroy => https://api.twitter.com/1.1/statuses/destroy/:id.json [here, we replace the id parameters])
			params: {
				// Use id_str instead of id ! id may be to long for an integer 
				id: JSON.parse(body).id_str
			}
		});
	}, 5000);
});


// Support of streaming api
var req = treq.request('statuses/filter', {
	// Add data to the body
	body: {
		'track': 'nodejs'
	}
});

req.on('data', function(data){
	console.log(data.toString());
});


// You can find and rewrite oauth data here (This object is passed to the request oauth function)
console.log(treq.oauth);
treq.oauth.consumer_key = "NEW_CONSUMER_KEY";

Keywords

twitter

FAQs

Package last updated on 05 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.