Skip to content

mkosir/twit-wrapper

Repository files navigation

twit-wrapper

npm Travis (.org)

Twitter API client for Node.js

This is a small utility wrapper/facade library which translates twit existing interface into simplified one.

Prerequisite

To interact with Twitter API, head over to Twitter Developer Platform and create new application.
Once you are done filling out information, you need to generate four access tokens:

  • Consumer API Key
  • Consumer API Secret Key
  • Access Token
  • Access Token Secret

Install

npm i twit-wrapper

Usage:

Only most commonly used function for interacting with Twitter API are implemented:

  • postTweet(msg)
  • getTweets(keyword, fromDate, lang = 'en', maxResults = 100)
const TwitterClient = require('twit-wrapper');
const twitterClient = new TwitterClient(
  consumerAPIKey,
  consumerAPISecretKey,
  accessToken,
  accessTokenSecret,
);

// post new tweet
try {
  const msgToPost = 'Post a test message';
  const postedMsg = await twitterClient.postTweet(msgToPost);
  console.log(postedMsg);
} catch (e) {
  console.error(e);
}

// search twitter for all tweets containing the word 'javascript' since January 1, 2017
try {
  const searchedTweets = await twitterClient.getTweets('javascript', '2017-01-01');
  console.log(searchedTweets);
} catch (e) {
  console.error(e);
}

Releases

No releases published