Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
uses Twitter API to grab all tweets in a collection
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
var maxPos = null;
var tweetCollection = [];
var collection_id = "custom-807057872278482944";
function scrapeTweets() {
if (maxPos) {
var params = {id: collection_id,
count: 200,
max_position: maxPos};
} else {
var params = {id: collection_id,
count: 200}
}
client.get('collections/entries', params, function(error, tweets, response) {
if (!error) {
if (tweets.response.position.was_truncated) maxPos = tweets.response.position.min_position;
tweets.response.timeline.forEach(function(tweet) {
tweetCollection.push("https://twitter.com/KSA_MissionCtrl/status/" + tweet.tweet.id);
});
if (tweets.response.position.was_truncated) scrapeTweets();
else console.log(tweetCollection);
} else {
throw error
}
});
}
scrapeTweets();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment