如何在Python中使用instagram-private-api获取所有关注者?

问题描述 投票:0回答:1

我尝试编写的代码需要一份关注我的所有帐户的列表,但我编写的代码仅准确地获得了 313 个帐户中的 193 个:

followers = api.user_followers(api.authenticated_user_id, rank_token = Client.generate_uuid())
myFollowers = []

for i in range(len(followers['users'])):
    myFollowers.append(followers['users'][i]['username'])

print(myFollowers)

我可以改变什么才能获得所有关注者?

python instagram instagram-api
1个回答
0
投票

您可以使用“max_id”参数获取所有用户。 请检查下面的代码。

myFollowers = []
next_max_id = "0"
while next_max_id != None :
    followers = api.user_followers(api.authenticated_user_id, rank_token = Client.generate_uuid(), max_id=next_max_id)
    next_max_id = followers.get('next_max_id')

    for i in range(len(followers['users'])):
        myFollowers.append(followers['users'][i]['username'])
print(myFollowers)
© www.soinside.com 2019 - 2024. All rights reserved.