Created
March 20, 2018 19:47
-
-
Save devonestes/8f778e3bda3570b669d3cbfc95f6ad35 to your computer and use it in GitHub Desktop.
Delete your old tweets
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
require 'twitter' | |
client = Twitter::REST::Client.new do |config| | |
config.consumer_key = "" | |
config.consumer_secret = "" | |
config.access_token = "" | |
config.access_token_secret = "" | |
end | |
def collect_with_max_id(collection=[], max_id=nil, &block) | |
response = yield(max_id) | |
collection += response | |
response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block) | |
end | |
def client.get_all_tweets(user) | |
collect_with_max_id do |max_id| | |
options = {count: 200, include_rts: true} | |
options[:max_id] = max_id unless max_id.nil? | |
user_timeline(user, options) | |
end | |
end | |
one_week_ago = (Time.now - 60 * 60 * 24 * 7) | |
all_tweets = client.get_all_tweets("devoncestes") | |
tweets_to_delete = all_tweets.select do |tweet| | |
tweet.created_at < one_week_ago | |
end | |
client.destroy_status(tweets_to_delete) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment