Home

TwitterRSSFeed: Twitter RSS feed Node.js library

npm version

Installation

$ npm install twitter-rss-feed

Usage

Creates a instance of TwitterRSSFeed

const TwitterRSSFeed = require('twitter-rss-feed');

const trf = new TwitterRSSFeed({
  consumer_key: 'YOUR_CONSUMER_KEY',
  consumer_secret: 'YOUR_CONSUMER_SECRET',
  token: 'YOUR_ACCESS_TOKEN',
  token_secret: 'YOUR_ACCESS_SECRET'
});

Uses statuses_user_timeline method

// parameters for Twitter API (GET statuses/user_timeline)
const params = {
  'screen_name' : 'YOUR_SCREEN_NAME',
  'count' : '20',
  'tweet_mode' : 'extended'
};

// information of RSS feed
const info = {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/YOUR_SCREEN_NAME'
  }
};

// create RSS feed
const rss = await trf.statuses_user_timeline(params, info);
console.log(rss);

Uses favorites_list method

// parameters for Twitter API (GET favorites/list)
const params = {
  'screen_name' : 'YOUR_SCREEN_NAME',
  'count' : '20',
  'tweet_mode' : 'extended'
};

// information of RSS feed
const info = {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/YOUR_SCREEN_NAME/likes'
  }
};

// set this filter to opts.filters
// if you want to extract only the tweets of public user's tweets
const opts = {
  'filters': [TwitterRSSFeed.public_users_filter()]
};

// create RSS feed
const rss = await trf.favorites_list(params, info, opts);
console.log(rss);

Uses search_tweets method

// parameters for Twitter API (Standard search API)
const params = {
  'q' : 'SEARCH_QUERY',
  'count' : '20',
  'tweet_mode' : 'extended'
};

// information of RSS feed
const info = {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/search?q=SEARCH_QUERY'
  }
};

// create RSS feed
const rss = await trf.search_tweets(params, info);
console.log(rss);

Uses get and rss methods

// path of Twitter API (Ex. 'statuses/user_timeline')
const path = 'statuses/user_timeline';

// parameters for Twitter API (GET statuses/user_timeline)
const params = {
  'screen_name' : 'YOUR_SCREEN_NAME',
  'count' : '20',
  'tweet_mode' : 'extended'
};

// get tweet objects
const tweets = await trf.get(path, params);

// information of RSS feed
const info = {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/YOUR_SCREEN_NAME'
  }
};

// options
const opts = {};

// create RSS feed
const rss = trf.rss(tweets, info, opts);
console.log(rss);

Uses formatter

// parameters for Twitter API (GET statuses/user_timeline)
const params = {
  'screen_name' : 'YOUR_SCREEN_NAME',
  'count' : '20',
  'tweet_mode' : 'extended'
};

// information of RSS feed
const info = {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/YOUR_SCREEN_NAME'
  }
};

// create formatter function
const my_formatter = function(tweet) {
  const text = tweet.full_text ? tweet.full_text : tweet.text;
  return {
    title: '@' + tweet.user.screen_name + ': "' + text + '" / Twitter',
    description: text,
    link: 'https://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id_str,
    date: new Date(tweet.created_at)
  };
};

// set your formatter to opts.formatter
const opts = {
  'formatter': my_formatter
};

// create RSS feed
const rss = await trf.statuses_user_timeline(params, info, opts);
console.log(rss);

Uses promise object

const promise = trf.statuses_user_timeline({
  'screen_name' : 'YOUR_SCREEN_NAME',
  'count' : '20',
  'tweet_mode' : 'extended'
}, {
  'channel' : {
    'title' : 'Your RSS feed title',
    'description' : 'Your RSS feed title',
    'link' : 'https://twitter.com/YOUR_SCREEN_NAME'
  },
});

promise
.then(function(rss) {
  console.log(rss);
})
.catch(function(error) {
  console.log(error);
});

Examples

Documentation

Development

Install dependent packages

$ npm install

Run testing

$ npm test

Install local for testing

Specify a local repository directory.

$ npm install ../twitter-rss-feed-nodejs/

Generate an API documentation

$ npm run jsdoc

Release

$ rm package-lock.json
$ rm -r node_modules/
$ npm publish
$ git tag -a vX.X.X -m "YOUR TAGGING MESSAGE"
$ git push origin tags/vX.X.X

License

The package is available as open source under the terms of the MIT License.