fetch-timeline

1.2.0 • Public • Published

fetch-timeline

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

Fetch Twitter user timeline using a readable stream.

Twitter API expose and endpoint called statuses/usertimeline to get the last Twitter users tweets, but is necessary concat the HTTP request to get more to 200 tweets per call (max to 3200).

This module encapsulate the logic to concatenate the HTTP requests.

Install

npm install fetch-timeline --save

Usage

const fetchTimeline = require('fetch-timeline')
 
const params = {
  screenName: 'kikobeats',
  count: 200
}
 
const opts = {
  credentials: {
    consumerKey: process.env.TWITTER_CONSUMER_KEY,
    consumerSecret: process.env.TWITTER_CONSUMER_SECRET,
    accessToken: process.env.TWITTER_ACCESS_TOKEN,
    accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET
  },
  limit: 3200,
  limitDays: 7
}
 
const stream = fetchTimeline(params, opts) // => Readable Stream
 
stream.on('data', (tweet, index) => {
  console.log(`#${++index} ${tweet.text}`)
})

The events available are:

.on('data')

Fire with each tweet fetched from the API endpoint.

.on('info')

Fired at the end of the timeline fetch process with meta information, such as:

{
  "user": "Object",
  "apiCalls": "Number",
  "count": "Number",
  "newerTweetDate": "Date",
  "olderTweetDate": "Date",
}

The rest of the readable event (error, end,...) have the expected behavior.

API

fetchTimeline(params, opts)

params

Represents the params necessary for setup the Twitter endpoint statuses/usertimeline for the API requests.

You need to specify the params using camelCase instead of snakeCase.

The library internally manage the cursor between successive API calls.

opts

credentials

Type: object

Represents the twit#credentials to connect with Twitter API.

limitDays

Type: number

Don't retrieve more older tweets than the number of days using Date.now() as baseline.

limit

Type: number

Use this value when you want to finish the process early, limiting the number of tweets to be fetched.

Examples

See fetch-timeline-cli#bin.

Related

License

MIT © Kiko Beats

Package Sidebar

Install

npm i fetch-timeline

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

19.1 kB

Total Files

7

Last publish

Collaborators

  • kikobeats