Search code examples
twitterapi-python

i want to mass follow twitter accounts but i got error that said i've requested to follow


So i want to mass follow people on Twitter with my account

but im kinda confused because i don't know how to fix the error, like i've requested to follow the "user", so what i want to do is skip the user if ive requested to follow them, but i dont know how to fix it, here's the code

`

following = api.get_friend_ids(screen_name = "2Wild2Crazy")

friends = api.get_friends(screen_name = "2Wild2Crazy", count = 200)

for i in range(len(friends)):
    print(""" " """, friends[i].screen_name, """ " """) 


#mass follow the people who follow 2Wild2Crazy
for i in range(len(friends)):
    api.create_friendship(screen_name = friends[i].screen_name)

`


Solution

  • Just do

    #mass follow the people who follow 2Wild2Crazy
    for i in range(len(friends)):
        try:
            api.create_friendship(screen_name = friends[i].screen_name)
        except tweepy.errors.Forbidden:
            print("Already following user: {}, skipping.".format(friends[i].screen_name))
    

    Might have to import tweepy to be able to except the error. If you don't like the print command you can replace it with pass that will tell python to just ignore that specific error.