public
Last active

download all public tweets of a twitter user

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
var http = require('http'),
querystring = require('querystring'),
fs = require('fs');
 
var screenname = '5000lobsters';
 
fs.mkdirSync(process.cwd() + '/tweets');
 
var getTweets = function(screenname, page) {
page = page || 0;
var query = {
screen_name: screenname,
page: page,
include_rts: false,
trim_user: true
};
var options = {
host: 'api.twitter.com',
port: 80,
path: '/1/statuses/user_timeline.json?' + querystring.stringify(query)
};
http.get(options, function(res) {
res.setEncoding('utf8');
var body = '';
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
var tweets = JSON.parse(body);
if (!tweets.length) {
return;
}
tweets.forEach(function(tweet) {
var path = [process.cwd(), 'tweets', tweet.id_str + '.json'].join('/');
console.log
fs.writeFileSync(path, JSON.stringify(tweet));
});
getTweets(screenname, page + 1);
});
});
};
 
getTweets(screenname);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.