Twitter API: Get a list of accounts that you follow but are not followed back

Twitter API: Get a list of accounts that you follow but are not followed back

The more followers you have, the harder it is to do this manually. It's a waste of time ... So I decided to make it semi-automated. In addition, since the number of followers has not reached 10,000 yet, I would like to manually perform the unfollowing work while actually visually observing the target account. Script up to get the account list.

Install python and PIP

Omitted

Install tweepy


$ pip install tweepy 

Have your Twitter API key handy

From https://developer.twitter.com/en/portal/dashboard. image.png

code

#unfollow_list.py
import tweepy
 
keys = dict(
    screen_name =         '[Twitter account name (screen_name)]',
    consumer_key =        '[Consumer key]',
    consumer_secret =     '[Consumer secret]',
    access_token =        '[Access token]',
    access_token_secret = '[Access token secret]',
)
 
SCREEN_NAME = keys['screen_name']
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_TOKEN = keys['access_token']
ACCESS_TOKEN_SECRET = keys['access_token_secret']
 
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
    
followers = api.followers_ids(SCREEN_NAME)
friends = api.friends_ids(SCREEN_NAME)


for f in friends:
    if f not in followers:
        print(api.get_user(f).screen_name)

Run


$ python unfollow_list.py

result

名称未設定.png

If you want to put it in a file, copy it.

Supplement

If you want the program to automatically remove it, add the api.destroy_friendship (f) statement after the print (api.get_user (f) .screen_name).


Recommended Posts

Twitter API: Get a list of accounts that you follow but are not followed back
[Linux] A list of unique command selections that are convenient but unexpectedly unknown
Get a list of GA accounts, properties, and views as vertical data using API
[Python] Get a list of folders only
Get a list of articles posted by users with Python 3 Qiita API v2
Use twitter API to get the number of tweets related to a certain keyword
Get a lot of Twitter tweets at once
Get a list of IAM users with Boto3
List of links that machine learning beginners are learning
Get a list of Qiita likes by scraping
I quarantined my environment with virtualenv, but I get a lot of packages with pip list