How to get only new followers using tweepy?

222 Views Asked by At

I need to only get the followers I have not fetched before. Currently I can only get the top 200 items or given count but I don't want to get the same data more than once.

2

There are 2 best solutions below

0
On

The only way I know how is to cycle through them and follow them if they haven't already been followed. I don't believe it's possible by looking at the API:

https://www.geeksforgeeks.org/python-api-followers-in-tweepy/

Make sure you have the third line for the API:

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth, wait_on_rate_limit = True)

Here's my snippet for following:

followers = tweepy.Cursor(api.get_followers).items()

for follower in followers:

if follower.id not in friends:

    user = api.get_user(follower.id)
    follower.follow()
2
On
followers = tweepy.Cursor(api.get_followers).items()

I just discovered that .items() can be passed a number. So you could do something like:

followers = tweepy.Cursor(api.get_followers).items(50)

Additionally, looking at the API documentation, API.get_followers() method, you can also set the number of followers to go through by passing a value to the count variable.

API.get_followers(*, user_id, screen_name, cursor, count, skip_status, include_user_entities)

API.get_followers(count=50)

The followers are returned in the number that they were added.