Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active May 4, 2023 13:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kristopherjohnson/1539be0108b16bed03858f3d12201bdd to your computer and use it in GitHub Desktop.
Save kristopherjohnson/1539be0108b16bed03858f3d12201bdd to your computer and use it in GitHub Desktop.
Unblock all blocked Twitter accounts
#!/usr/bin/env python3
# Dependency: pip3 install twitter
import twitter
# Go to http://apps.twitter.com/, create an app, and fill in these values:
consumer_key = 'www'
consumer_secret = 'xxx'
access_token = 'yyy'
access_token_secret = 'zzz'
def twitter_login():
"""Connect to Twitter, returning a Twitter instance."""
auth = twitter.OAuth(access_token, access_token_secret, consumer_key, consumer_secret)
return twitter.Twitter(auth=auth, retry=True)
def unblock_all(t):
"""Unblock all blocked accounts, using the given Twitter instance."""
blocked_count = 0
while True:
blocked_user_ids = t.blocks.ids()["ids"]
if not blocked_user_ids:
print("No more IDs to unblock")
break
for user_id in blocked_user_ids:
blocked_count = blocked_count + 1
print(f"{blocked_count}: {user_id}")
try:
t.blocks.destroy(user_id=user_id, include_entities=False, skip_status=True)
except:
print("error")
if __name__ == "__main__":
t = twitter_login()
unblock_all(t)
@nathanwentworth
Copy link

thank you for this!

@erbanku
Copy link

erbanku commented Jun 20, 2022

Awesome, thanks!

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