Created
February 19, 2020 19:01
-
-
Save KSAMissionCtrl/1b066489c7010448b3c73cd4a6bb9dd4 to your computer and use it in GitHub Desktop.
uses Twitter API to grab all tweets in a collection
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
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