8

Twitter recently rolled out a redesign of their desktop website interface, and the ability to export and import my block list seems to have been removed. Exporting/importing my block list was useful in archiving or sharing (with my other accounts, or with others' accounts).

Previously, I could view my block list by clicking "Settings and privacy -> Blocked accounts", which led to https://twitter.com/settings/blocked. There was a dropdown-link labeled "Advanced options" that revealed an option to "Export your list", which downloaded as a CSV file of a single column of many numbers (presumably user IDs).

old screenshot

In the new (2019) Twitter interface, I can view my block list by clicking "Settings -> Privacy and safety -> Blocked accounts", which leads to https://twitter.com/settings/blocked/all. There is no tool I see for exporting or importing my block list, only to view all or view imported.

new screenshot

I don't see this data in Twitter's "Settings -> Account -> Your Twitter data" download either.

Navigating to the old URL takes me to the new URL.

Anyone know a way to export my personal block list from Twitter now?

3 Answers 3

3

This facility is "not currently available", unfortunately. Maybe keep an eye on this page:

https://help.twitter.com/en/using-twitter/advanced-twitter-block-options#

2

The way I did it wasn't pretty, but they severely limited our options by removing the export/import block list functionality.

I requested my Data Archive (https://help.twitter.com/en/managing-your-account/how-to-download-your-twitter-archive). You'll notice that it only contains link out to the web version of the block list. Since that list is dynamically loaded, it is not easy to web scrape without Selenium or a proxy, and it will get ugly.

So, instead, I dug around in the Data Archive and eventually found block.js, which is a JSON object of all the blocked accounts in their ideas. From there you can write a quick Python script to use the Twitter API to resolve all of those IDs to usernames.

Once I get home I'll edit this comment to include the Python I used for this.

EDIT: Here is the script:

// Burninator 2022 // Export block list functionality that Twitter randomly removed // Used to block all the promoted content, will be posting a list of about 5000 blocked accounts shortly

from requests_oauthlib import OAuth1Session
import os
import json
import time


def getblocklist(fancyfile):
    consumer_key = "HAHA"
    consumer_secret = "NICETRYHACKERS"

    # Get request token
    request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write"
    oauth = OAuth1Session(consumer_key, client_secret=consumer_secret)

    try:
        fetch_response = oauth.fetch_request_token(request_token_url)
    except ValueError:
        print(
            "There may have been an issue with the consumer_key or consumer_secret you entered."
        )

    resource_owner_key = fetch_response.get("oauth_token")
    resource_owner_secret = fetch_response.get("oauth_token_secret")
    print("Got OAuth token: %s" % resource_owner_key)

    # Get authorization
    base_authorization_url = "https://api.twitter.com/oauth/authorize"
    authorization_url = oauth.authorization_url(base_authorization_url)
    print("Please go here and authorize: %s" % authorization_url)
    verifier = input("Paste the PIN here: ")

    # Get the access token
    access_token_url = "https://api.twitter.com/oauth/access_token"
    oauth = OAuth1Session(
        consumer_key,
        client_secret=consumer_secret,
        resource_owner_key=resource_owner_key,
        resource_owner_secret=resource_owner_secret,
        verifier=verifier,
    )
    oauth_tokens = oauth.fetch_access_token(access_token_url)

    access_token = oauth_tokens["oauth_token"]
    access_token_secret = oauth_tokens["oauth_token_secret"]

    # Make the request
    oauth = OAuth1Session(
        consumer_key,
        client_secret=consumer_secret,
        resource_owner_key=access_token,
        resource_owner_secret=access_token_secret,
    )

    logMe = open(fancyfile, 'r') #Block.js from user's data archive download
    leoutput = open("block_names.txt", 'a') #save account names here
    thecounter = 1

    for line in logMe:
        thatsTheTweet = "Current blocked account ID: " + line
        line = line.strip()
        thecounter = thecounter + 1

        # Making the request
        response = oauth.get(
            "https://api.twitter.com/2/users/"+line+"?user.fields=name"
        )

        #print (str(response.content))
        if (response.status_code != 201) and (response.status_code != 200):
            print("Request returned an error: {} {}".format(response.status_code, response.text))

        if ("Not Found Error" in response.text):
            print("Response code User Not Found: {}".format(response.status_code))
            continue

        if ("Forbidden" in response.text):
            print("Response code Forbidden: {}".format(response.status_code))
            continue

        if response.status_code == 429:
            print("Response code 429 usually is rate limit: {}".format(response.status_code))
            logMe.close()
            leoutput.close()
            exit(1337)


        print("Response code: {}".format(response.status_code))

        # Saving the response as JSON
        json_response = response.json()
        print(json.dumps(json_response, indent=4, sort_keys=True))

        snarf= json.dumps(json_response, indent=4, sort_keys=True)
        thejson = json.loads(snarf)
        writeme = thejson['data']['username'] #     "data" "username"
        leoutput.write(writeme+"\n")

        if (thecounter < 200):
            time.sleep(20)  # make it 20, 38 wroks
        else:
            time.sleep(63)

    logMe.close()
    leoutput.close()
    print("done")
    exit(1338)


if __name__ == '__main__':
    getblocklist('firstshot_twitter_block_reduced.txt')

https://burninatorsec.blogspot.com/2022/07/twitter-removed-blocked-account-export.html

2
  • Thanks for including the link to your code. Would you please add the code to your answer. Regrettably, external resources sometimes become unreachable or go permanently offline. The link is helpful, but it's always better to include as much information in your answer, and avoid making it necessary to click on links as much as possible.
    – Tedinoz
    Jul 27, 2022 at 10:49
  • No problem, thanks for the head's up, I'll add it now
    – burninator
    Jul 27, 2022 at 19:21
-1

The feature is still available, though unofficially. Just set up a browser extension switching Twitter to the pre-2019 design:

...and the Import/Export is still there as it was.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.