Como apagar seus tweets em poucos passos.
Eu e a @AlineMary decidimos mudar o rumo no Twitter. Antes, tínhamos um perfil privado, restrito a alguns conhecidos. Por motivos pessoais, resolvemos que vamos utilizar o Twitter de forma mais publica e mais voltada a nossos projetos.
Só um porém: não gostaríamos de perder nossos seguidores e aqueles os quais seguíamos, portanto deletar e recriar a conta era algo impraticável. Deletar manualmente os tweets, também (eu tinha ~ 9800 tweets e ela ~ 600).
Procurei vários serviços de mass delete na web e achamos alguns muito bem recomendados. O problema é que eles simplesmente não funcionaram ![]()
Sempre unida de uma sabedoria cativante, @AlineMary falou: “Você não é um programador?”. Point taken, my dear ![]()
Após efetuar algumas buscas na web por uma API simples de usar (e com suporte a OAuth), achei o artigo do Jeff Miller – “Twitter from the command line in Python using OAuth”, o qual demonstrava o uso muito simples da API Tweepy.
Dando uma olhada rápida na documentação e seguindo o exemplo do Jeff, montei um programa bem bare bones para remoção em massa dos tweets. E não é que deu certo? ![]()
Vamos aos passos. Iniciamente você terá de seguir as etapas do post do Jeff para efetuar a autenticação OAuth no Twitter.
Step 1: Download Tweepy
Tweepy is an awesome Twitter library for Python. Much of this post is based on information I found in the Tweepy documentation.
Download Tweepy from GitHub and install it on your system.
Step 2: Register a new client app with Twitter
Navigate to http://twitter.com/oauth_clients and click on Register a new application. You might have to log in to the Twitter site first, if you’re not already.
Fill in the registration fields as follows:
When finished on the registration page, click Save.
Next page:
Keep this browser window open. We’ll need the information in the next step.
Step 3: Connect the app to your Twitter account
Next, the app needs to be authorized to connect to your account so it can send tweets under your name.
We’ll create a one-off utility script to do this. Save the following Python code as a script on your local system.
#!/usr/bin/env python import tweepy CONSUMER_KEY = 'paste your Consumer Key here' CONSUMER_SECRET = 'paste your Consumer Secret here' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth_url = auth.get_authorization_url() print 'Please authorize: ' + auth_url verifier = raw_input('PIN: ').strip() auth.get_access_token(verifier) print "ACCESS_KEY = '%s'" % auth.access_token.key print "ACCESS_SECRET = '%s'" % auth.access_token.secretPaste the Consumer Key and Consumer Secret from the end of step 2 into this script, replacing the CONSUMER_KEY and CONSUMER_SECRET constants. Then save and run on your system.
You should see a prompt like this:
Please authorize: <URL> PIN:Open that URL in your browser. You should see the standard OAuth Twitter connection screen:
Click Allow.
Twitter will then provide you with a PIN code that authenticates the connection between the client app and your Twitter account.
Enter this PIN into the prompt from the Python registration script:
PIN: 2781961The script will then print out another key/secret pair:
ACCESS_KEY = '124242RCyi3g0cZ4r5BWL047rsh0S0yv5VxAGwTKCOsHAb' ACCESS_SECRET = 'kaTXiC489qo8y6haTBSlwOqR1syG83tzPG2StdQ'But the values will be different each time.
Keep this information on your screen because we’ll need it in the next step.
Ok! Obrigado Jeff
Agora, vamos a parte destruidora do Post. Muahuahua*.
Vamos criar um script simples que vai iterar pelos posts já efetuados pelo seu usuário e… bem, deletá-los ![]()
#!/usr/bin/env python import sys import tweepy import time CONSUMER_KEY = 'xxxxxxxx' CONSUMER_SECRET = 'xxxxxxxx' ACCESS_KEY = 'xxxxxxxxx' ACCESS_SECRET = 'xxxxxxxxxxxx' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) api = tweepy.API(auth) pag = 1 status = [] while (1): try: status = api.user_timeline(page=pag) for update in status: print update.id print update.text api.destroy_status(update.id) print "--" pag = pag + 1 except: print "Failure... sleeping for 10 minutes." time.sleep(600) # Sleep for 10 minutes and try again.
E é isso. Execute esse script Python informando as Keys e Secrets obtidas em cima com o Jeff e… aguarde. O script demora um bocado (o meu ainda está rodando). Mas funciona 100% ![]()
Dúvidas? Comment!
* Frase atribuída a Sheldon Cooper. 
Syndicated 2010-10-19 15:40:58 (Updated 2010-10-25 22:45:08) from #include "ebf.h"




