forked from tmhlsky/Instagram-API-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_followers.py
More file actions
42 lines (32 loc) · 1.17 KB
/
Copy pathuser_followers.py
File metadata and controls
42 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password
from InstagramAPI import InstagramAPI
def getTotalFollowers(api, user_id):
"""
Returns the list of followers of the user.
It should be equivalent of calling api.getTotalFollowers from InstagramAPI
"""
followers = []
next_max_id = True
while next_max_id:
# first iteration hack
if next_max_id is True:
next_max_id = ''
_ = api.getUserFollowers(user_id, maxid=next_max_id)
followers.extend(api.LastJson.get('users', []))
next_max_id = api.LastJson.get('next_max_id', '')
return followers
if __name__ == "__main__":
api = InstagramAPI("username", "password")
api.login()
# user_id = '1461295173'
user_id = api.username_id
# List of all followers
followers = getTotalFollowers(api, user_id)
print('Number of followers:', len(followers))
# Alternatively, use the code below
# (check evaluation.evaluate_user_followers for further details).
followers = api.getTotalFollowers(user_id)
print('Number of followers:', len(followers))