Skip to content

Instantly share code, notes, and snippets.

@thebigbad
Created February 4, 2012 06:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebigbad/1735965 to your computer and use it in GitHub Desktop.
Save thebigbad/1735965 to your computer and use it in GitHub Desktop.
download all public tweets of a twitter user
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment