question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unfollowing people not following me ... script not working

See original GitHub issue

So, I have been at this for days and it seems that there is no way to unfollow people who are not following me…

twitter_handle = "MyTwitterName" 

friends_ids = api.friends_ids(api.me().id)

for follower in tweepy.Cursor(api.followers, id=twitter_handler).items():
    if follower.id not in friends_ids:
        api.destroy_friendship(follower)

I have tried many variations of the above script bit it does not work.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Peerdixcommented, Feb 13, 2022

I saw you are using tweepy as a python lib. i spontanly wrote this using python 2.7 You don’t have to seperate the dict. key from the main file, just a matter style. I did a sleep method from lib “time” to prevent twitter from spotting you as a bot.

If you have any questions, just ask.

#! /usr/bin/python
import tweepy
import random
from keys import keys
import time

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 f
        print "Unfollow {0}".format(api.get_user(f).screen_name)
        api.destroy_friendship(f)
        nsecs=random.randint(5,25)
        time.sleep(nsecs)
    else:
        continue


##keys.py

keys = dict(
    screen_name = 'Twitter handle',
    consumer_key =          '',
    consumer_secret =       '',
    access_token =          '',
    access_token_secret =   '',
)


0reactions
Harmon758commented, Feb 13, 2022

API.friends_ids, now renamed to API.get_friend_ids, returns the IDs of users being followed by the specified user, whereas API.followers, now renamed to API.get_followers returns the specified user’s followers.

Also, the Twitter API endpoint that API.friends_ids, now renamed to API.get_friend_ids, uses, GET friends/ids, only returns 5000 user IDs at a time.

You’re iterating through all the followers of the specified user and checking to see if they’re one of your 5000 most recent followed users and if not, attempting to unfollow them.

It’s unclear what you’re attempting to try to do. If the specified user is the one you’re authenticated as, then there will be no users not following you when iterating through all your followers. If you’re attempting to go through the users you’re following and unfollow those not following you, as your title would suggest, then you’re iterating over the wrong set of users. Instead, you probably want to iterate over all the users you’re following and use API.lookup_friendships or API.get_friendship to determine whether or not they’re following you. That or you can retrieve all your followers beforehand to check if each user is in that group, i.e. following you.

@Peerdix @yogeshdmca @PvrpleBlvck CC @ChadLei That will only handle the most recent 5000 followers and following.

@PvrpleBlvck For code block usage, see https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unfollow users who are not following you back on instagram
Automate instagram with this python automation projectThis video is about how to automate instagram with python , basically we are going to ...
Read more >
How to unfollow users that don't follow me on Instagram - Quora
You're going to have to go to your profile, click on your followers, and then go through the whole list and individually unfollow...
Read more >
How to unfollow everyone on Instagram at once - Taplink
Go to the first section and unfollow from those accounts that you are not interested in.
Read more >
tiktok unfollow tracker - Caseificio de Nicola
Tik-Followers is a 3rd party app that allows you to track your followers, those who have blocked you, and those who have unfollowed...
Read more >
'Who Unfollowed Me on Instagram?': Here Are the Apps That ...
How to Check Unfollows Using an App; ​​How to Check Who Isn't Following You Back Using an App. Recent Changes to Instagram. Instagram...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found