Skip to content

Instantly share code, notes, and snippets.

@KSAMissionCtrl
Created February 19, 2020 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KSAMissionCtrl/1b066489c7010448b3c73cd4a6bb9dd4 to your computer and use it in GitHub Desktop.
Save KSAMissionCtrl/1b066489c7010448b3c73cd4a6bb9dd4 to your computer and use it in GitHub Desktop.
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