ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.94k stars 608 forks source link

Followers Pagination #403

Open 808arc opened 1 year ago

808arc commented 1 year ago

Hi guys! im new to coding and I was reading documentation and build this script to get list of followers but I keep getting errors. Can some one please explain me what im doing wrong and why?

from instagram_private_api import Client, ClientCompatPatch

user_name = '***'
password = '***'

api = Client(user_name, password)

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))
print(usernames)
808arc commented 1 year ago

Hi! Im going test this code asap! Kindly thank you for showing me how it can work in that way <3