Skip to content

Instantly share code, notes, and snippets.

@devonestes
Created March 20, 2018 19:47
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 devonestes/8f778e3bda3570b669d3cbfc95f6ad35 to your computer and use it in GitHub Desktop.
Save devonestes/8f778e3bda3570b669d3cbfc95f6ad35 to your computer and use it in GitHub Desktop.
Delete your old tweets
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