Skip to content

Commit ba896a3

Browse files
committed
Add some functions:
removeProfilePicture, setPrivateAccount, setPublicAccount, getProfileData, editProfile, getUsernameInfo, getSelfUsernameInfo, getFollowingRecentActivity, getUserTags, getSelfUserTags.
1 parent efce6a6 commit ba896a3

File tree

2 files changed

+94
-12
lines changed

2 files changed

+94
-12
lines changed

InstagramAPI.py

+72-8
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ def login(self, force = False):
5757
'login_attempt_count' : '0'}
5858

5959
if (self.SendRequest('accounts/login/', self.generateSignature(json.dumps(data)), True)):
60-
print ("Login success!")
6160
self.isLoggedIn = True
6261
self.username_id = self.LastJson["logged_in_user"]["pk"]
63-
print (self.username_id)
6462
self.rank_token = "%s_%s" % (self.username_id, self.uuid)
6563
self.token = self.LastResponse.cookies["csrftoken"]
6664

@@ -69,7 +67,7 @@ def login(self, force = False):
6967
self.timelineFeed()
7068
self.getv2Inbox()
7169
self.getRecentActivity()
72-
70+
print ("Login success!\n")
7371
return True;
7472

7573
def tagFeed(self, tag):
@@ -239,20 +237,86 @@ def deleteComment(self, mediaId, captionText, commentId):
239237
})
240238
return self.SendRequest("media/"+ str(mediaId) +"/comment/"+ str(commentId) +"/delete/", self.generateSignature(data))
241239

242-
def changeProfilePicture(photo):
240+
def changeProfilePicture(self, photo):
243241
# TODO Instagram.php 705-775
244242
return False
245243

246-
def getv2Inbox(self):
247-
inbox = self.SendRequest('direct_v2/inbox/?')
248-
# TODO Instagram.php 950-960
249-
return inbox
244+
def removeProfilePicture(self):
245+
data = json.dumps({
246+
'_uuid' : self.uuid,
247+
'_uid' : self.username_id,
248+
'_csrftoken' : self.token
249+
})
250+
return self.SendRequest("accounts/remove_profile_picture/", self.generateSignature(data))
251+
252+
def setPrivateAccount(self):
253+
data = json.dumps({
254+
'_uuid' : self.uuid,
255+
'_uid' : self.username_id,
256+
'_csrftoken' : self.token
257+
})
258+
return self.SendRequest("accounts/set_private/", self.generateSignature(data))
259+
260+
def setPublicAccount(self):
261+
data = json.dumps({
262+
'_uuid' : self.uuid,
263+
'_uid' : self.username_id,
264+
'_csrftoken' : self.token
265+
})
266+
return self.SendRequest("accounts/set_public/", self.generateSignature(data))
267+
268+
def getProfileData(self):
269+
data = json.dumps({
270+
'_uuid' : self.uuid,
271+
'_uid' : self.username_id,
272+
'_csrftoken' : self.token
273+
})
274+
return self.SendRequest("accounts/current_user/?edit=true", self.generateSignature(data))
275+
276+
def editProfile(self, url, phone, first_name, biography, email, gender):
277+
data = json.dumps({
278+
'_uuid' : self.uuid,
279+
'_uid' : self.username_id,
280+
'_csrftoken' : self.token,
281+
'external_url' : url,
282+
'phone_number' : phone,
283+
'username' : self.username,
284+
'full_name' : first_name,
285+
'biography' : biography,
286+
'email' : email,
287+
'gender' : gender,
288+
})
289+
return self.SendRequest("accounts/edit_profile/", self.generateSignature(data))
290+
291+
def getUsernameInfo(self, usernameId):
292+
return self.SendRequest("users/"+ str(usernameId) +"/info/")
250293

251294
def getRecentActivity(self):
252295
activity = self.SendRequest('news/inbox/?')
253296
# TODO Instagram.php 911-925
254297
return activity
255298

299+
def getFollowingRecentActivity(self):
300+
activity = self.SendRequest('news/?')
301+
# TODO Instagram.php 935-945
302+
return activity
303+
304+
def getv2Inbox(self):
305+
inbox = self.SendRequest('direct_v2/inbox/?')
306+
# TODO Instagram.php 950-960
307+
return inbox
308+
309+
def getUserTags(self, usernameId):
310+
tags = self.SendRequest('usertags/'+ str(usernameId) +'/feed/?rank_token='+ self.rank_token +'&ranked_content=true&')
311+
# TODO Instagram.php 975-985
312+
return tags
313+
314+
def getSelfUserTags(self):
315+
return self.getUserTags(self.username_id)
316+
317+
def getSelfUsernameInfo(self):
318+
return self.getUsernameInfo(self.username_id)
319+
256320
InstagramAPI = InstagramAPI("login", "password")
257321
InstagramAPI.login() # login
258322
InstagramAPI.tagFeed("cat") # get media list by tag #cat

README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is python port of https://github.com/mgp25/Instagram-API, written on PHP. W
1111

1212
1) login;
1313

14-
2) tagFeed;
14+
2) tagFeed (TODO);
1515

1616
3) like;
1717

@@ -31,9 +31,9 @@ This is python port of https://github.com/mgp25/Instagram-API, written on PHP. W
3131

3232
11) deleteMedia;
3333

34-
12) getv2Inbox;
34+
12) getv2Inbox (TODO);
3535

36-
13) getRecentActivity;
36+
13) getRecentActivity (TODO);
3737

3838
14) megaphoneLog;
3939

@@ -43,7 +43,25 @@ This is python port of https://github.com/mgp25/Instagram-API, written on PHP. W
4343

4444
17) syncFeatures;
4545

46-
18)
46+
18) removeProfilePicture;
47+
48+
19) setPrivateAccount;
49+
50+
20) setPublicAccount;
51+
52+
21) getProfileData;
53+
54+
22) editProfile;
55+
56+
23) getUsernameInfo;
57+
58+
24) getSelfUsernameInfo;
59+
60+
25) getFollowingRecentActivity (TODO);
61+
62+
26) getUserTags (TODO);
63+
64+
27) getSelfUserTags;
4765

4866
### TODO:
4967

0 commit comments

Comments
 (0)