Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A quick way to delete all your tweets using Twitter archive and a ruby script.
require 'twitter'
require "json"
USERNAME = 'YOUR_TWITTER_USER_NAME'
ARCHIVE_PATH = 'archive/data/js/tweets'
client = Twitter::REST::Client.new do |config|
config.consumer_key = 'TWITTER_APP_API_KEY'
config.consumer_secret = 'TWITTER_APP_API_SECRET'
config.access_token = 'TWITTER_APP_ACCESS_TOKEN'
config.access_token_secret = 'TWITTER_APP_ACCESS_TOKEN_SECRET'
end
Dir.foreach(ARCHIVE_PATH) do |item|
unless (item == '.') or (item == '..') or (item == '.DS_Store')
#ignore system files and paths
file = File.readlines("#{ARCHIVE_PATH}/#{item}")[1..-1].join()
data = JSON.parse(file)
data.each do |tweet|
removeId = tweet['id']
begin
client.destroy_status(removeId)
puts "destroyed tweet_id: #{removeId}"
rescue => e
puts "ooops: #{e} -- t_id: #{removeId}"
end
end
sleep(60)
end
end
@kirillzubovsky

This comment has been minimized.

Show comment Hide comment
@kirillzubovsky

kirillzubovsky Jun 5, 2014

To make this script work you first need to do two things on Twitter: (1) download your Archive and (2) create an app that is able to delete your own tweets. For more details, I've written a short post on how to delete your tweets using Ruby. Enjoy!

Owner

kirillzubovsky commented Jun 5, 2014

To make this script work you first need to do two things on Twitter: (1) download your Archive and (2) create an app that is able to delete your own tweets. For more details, I've written a short post on how to delete your tweets using Ruby. Enjoy!

@Rishi333

This comment has been minimized.

Show comment Hide comment
@Rishi333

Rishi333 Sep 16, 2016

Great Script, works like a charm. I just wish I read the script first. I thought you wanted the PATH_TO_TWEET_ARCHIVE to point to the folder that twitter gave you as a download. I later realized you wanted the actual subdirectory that pointed to tweets in json format.

Great Script, works like a charm. I just wish I read the script first. I thought you wanted the PATH_TO_TWEET_ARCHIVE to point to the folder that twitter gave you as a download. I later realized you wanted the actual subdirectory that pointed to tweets in json format.

@kirillzubovsky

This comment has been minimized.

Show comment Hide comment
@kirillzubovsky

kirillzubovsky Dec 29, 2016

@Rishi333 good point. I will rework it to be more obvious.

Owner

kirillzubovsky commented Dec 29, 2016

@Rishi333 good point. I will rework it to be more obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment