Skip to content

Commit

Permalink
Merge pull request #137 from xecgr/master
Browse files Browse the repository at this point in the history
close issue getUserFollowings outdated #133
  • Loading branch information
LevPasha authored May 3, 2017
2 parents 018a4f8 + dcc4686 commit 7123f41
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
12 changes: 10 additions & 2 deletions InstagramAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,16 @@ def getPopularFeed(self):
return popularFeed

def getUserFollowings(self, usernameId, maxid = ''):
return self.SendRequest('friendships/'+ str(usernameId) +'/following/?max_id='+ str(maxid)
+'&ig_sig_key_version='+ self.SIG_KEY_VERSION +'&rank_token='+ self.rank_token)
url = 'friendships/'+ str(usernameId) +'/following/?'
query_string = {
'ig_sig_key_version': self.SIG_KEY_VERSION,
'rank_token' : self.rank_token,
}
if maxid:
query_string['max_id'] = maxid
url += urllib.urlencode(query_string)

return self.SendRequest(url)

def getSelfUsersFollowing(self):
return self.getUserFollowings(self.username_id)
Expand Down
28 changes: 28 additions & 0 deletions examples/user_followings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from InstagramAPI import InstagramAPI
import time
from datetime import datetime

username = ''
pwd = ''
user_id = '19343908'


API = InstagramAPI(username,pwd)
API.login()

following = []
next_max_id = True
while next_max_id:
print next_max_id
#first iteration hack
if next_max_id == True: next_max_id=''
_ = API.getUserFollowings(user_id,maxid=next_max_id)
following.extend ( API.LastJson.get('users',[]))
next_max_id = API.LastJson.get('next_max_id','')

len(following)
unique_following = {
f['pk'] : f
for f in following
}
len(unique_following)

0 comments on commit 7123f41

Please sign in to comment.