Created
March 31, 2017 00:23
-
-
Save doingweb/86d929109362010d19d9b9858f4070e6 to your computer and use it in GitHub Desktop.
Print all your twitters!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Twitter = require('twitter'); | |
let client = new Twitter({ | |
consumer_key: process.env.TWITTER_CONSUMER_KEY, | |
consumer_secret: process.env.TWITTER_CONSUMER_SECRET, | |
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, | |
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET | |
}); | |
async function getTwitters (maxId) { | |
let params = { | |
screen_name: 'doingweb', | |
count: 200 | |
}; | |
if (maxId) { | |
params.max_id = maxId; | |
} | |
let result = await client.get('statuses/user_timeline', params); | |
return result.map(t => ({ id: t.id_str, text: t.text })); | |
} | |
async function printAllTheTwitters () { | |
let allTwitters = []; | |
let lastId = null; | |
while (lastId !== undefined) { | |
let twitters = await getTwitters(lastId); | |
if (lastId) { | |
twitters.shift(); | |
} | |
console.log(twitters.map(t => t.text.trim()).join('\n')); | |
let lastTwitter = twitters[twitters.length-1]; | |
lastId = lastTwitter && lastTwitter.id; | |
} | |
} | |
printAllTheTwitters(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment