Reputation: 97
I find very cool library called Instagram Private Api and Im trying get all people subscribed on my Instagram for educational purposes. But I can't get more than 100 units :( Can somebody help me understand how to fix it?
from random import randint
from time import sleep
user_id = api.username_info('target')['user']['pk']
# Create a list of followers' usernames
usernames = []
next_max_id = followers.get('next_max_id')
while next_max_id:
delay = randint(20,40)
print("Sleep " + str(delay) + "s")
sleep(delay)
# Get a list of the user's followers
followers = api.user_followers(user_id, rank_token=api.generate_uuid(),)
next_max_id = followers.get('next_max_id')
for follower in followers['users']:
usernames.append(follower['username'])
# Print the list of followers' usernames
print(len(usernames))```
Upvotes: 0
Views: 952
Reputation: 154
This works for me:
from instagram_private_api import Client, ClientCompatPatch
username = 'username'
password = 'password'
def get_all_followers(api, user_id, rank_token):
followers = []
next_max_id = True
while next_max_id:
if next_max_id == True:
result = api.user_followers(user_id, rank_token)
else:
result = api.user_followers(user_id, rank_token, max_id=next_max_id)
next_max_id = result.get('next_max_id')
followers.extend([user['username'] for user in result['users']])
return followers
if __name__ == '__main__':
api = Client(username, password)
user_info = api.username_info(username)
user_id = user_info['user']['pk']
rank_token = Client.generate_uuid()
followers = get_all_followers(api, user_id, rank_token)
Upvotes: 1
Reputation: 336
From the documentation: you can pass max_id
to offset the selection of users.
You can also look at the provided example.
Upvotes: 2