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.
npm install fetch-timeline --save
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:
Fire with each tweet fetched from the API endpoint.
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.
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.
Type: object
Represents the twit#credentials to connect with Twitter API.
Type: number
Don't retrieve more older tweets than the number of days using Date.now()
as baseline.
Type: number
Use this value when you want to finish the process early, limiting the number of tweets to be fetched.
- fetch-timeline-cli – Fetch the timeline of a Twitter user from your terminal.
- tweets-microservice – Twitter timeline fetcher as service.
MIT © Kiko Beats