Coder Social home page Coder Social logo

twitterrecover's Introduction

My twitter account is hacked by someone few days ago. He tweeted 500+ messages in Russian with links, and followed 300+ honeypots.

So I have to remove all my tweets and clean my following list.

First, create an application in Twitter, and use the scripts to get oauth. The script requires requests along with requests-oauthlib.

After you: oauth = get_oauth() you can use

requests.get(url=get_url, auth=oauth)

or

request.post(url=post_url, auth=oauth, data=post_data)

to get and send message using Twitter API

Take me (@vancexu) as an example, the following code remove all my 300+ followings in 1 minutes.

get_url = 'https://api.twitter.com/1.1/friends/ids.json?cursor=-1&screen_name=vancexu'
r = requests.get(url=get_url, auth=oauth)
res = r.json()
ids = res['ids'] # get the ids of who I followed
post_url = 'https://api.twitter.com/1.1/friendships/destroy.json'
for id in ids:
    # each post request will delete one id I followed
    requests.post(url=post_url, auth=oauth, data={'user_id': str(id)}

The following code remove 200 of my tweets one time

get_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=vancexu&count=500'
r = requests.get(url=get_url, auth=oauth)
res = r.json()
ids = []
# get all tweets' ids
for i in res:
    ids.append(i['id_str'])

post_url = 'https://api.twitter.com/1.1/statuses/destroy/'
for i in ids:
    # remove one tweet at a time, according to the given tweet id.
    requests.post(url=post_url+i+'.json', auth=oauth)

reference: http://thomassileo.com/blog/2013/01/25/using-twitter-rest-api-v1-dot-1-with-python/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.