Skip to content

Commit 7123f41

Browse files
authored
Merge pull request #137 from xecgr/master
close issue getUserFollowings outdated #133
2 parents 018a4f8 + dcc4686 commit 7123f41

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

InstagramAPI.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,16 @@ def getPopularFeed(self):
524524
return popularFeed
525525

526526
def getUserFollowings(self, usernameId, maxid = ''):
527-
return self.SendRequest('friendships/'+ str(usernameId) +'/following/?max_id='+ str(maxid)
528-
+'&ig_sig_key_version='+ self.SIG_KEY_VERSION +'&rank_token='+ self.rank_token)
527+
url = 'friendships/'+ str(usernameId) +'/following/?'
528+
query_string = {
529+
'ig_sig_key_version': self.SIG_KEY_VERSION,
530+
'rank_token' : self.rank_token,
531+
}
532+
if maxid:
533+
query_string['max_id'] = maxid
534+
url += urllib.urlencode(query_string)
535+
536+
return self.SendRequest(url)
529537

530538
def getSelfUsersFollowing(self):
531539
return self.getUserFollowings(self.username_id)

examples/user_followings.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from InstagramAPI import InstagramAPI
2+
import time
3+
from datetime import datetime
4+
5+
username = ''
6+
pwd = ''
7+
user_id = '19343908'
8+
9+
10+
API = InstagramAPI(username,pwd)
11+
API.login()
12+
13+
following = []
14+
next_max_id = True
15+
while next_max_id:
16+
print next_max_id
17+
#first iteration hack
18+
if next_max_id == True: next_max_id=''
19+
_ = API.getUserFollowings(user_id,maxid=next_max_id)
20+
following.extend ( API.LastJson.get('users',[]))
21+
next_max_id = API.LastJson.get('next_max_id','')
22+
23+
len(following)
24+
unique_following = {
25+
f['pk'] : f
26+
for f in following
27+
}
28+
len(unique_following)

0 commit comments

Comments
 (0)