Skip to content

Commit

Permalink
Add get_session_id method.
Browse files Browse the repository at this point in the history
Add get_session_id method to get the session ID of a logged in session OR a new session. Add get_session_id method to docs.
  • Loading branch information
iSarabjitDhiman committed Jun 16, 2023
1 parent 719802b commit 4d53b44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions instagpy/docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ login(username=None, password=None, show_saved_sessions=False, save_session=True
"""
```

## Get Session ID.

```python
get_session_id(self, username=None, password=None, new_session=False)

"""
Get sessionID of the current session OR a new login session. By default returns current one if logged in.
Args:
username (str): Username OR Email. Defaults to None
password (str): Password. Defaults to None
new_session (bool, optional): Set to True if want to get session ID from a new session. Otherwise It will return the already logged In session ID. Defaults to False.
Returns:
str: Session ID.
"""
```

## Get Logged In User Details.

```python
Expand Down
19 changes: 19 additions & 0 deletions instagpy/instagpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ def logged_in(self):
return True
return False

def get_session_id(self, username=None, password=None, new_session=False):
"""Get sessionID of the current session OR a new login session. By default returns current one if logged in.
Args:
username (str): Username OR Email.
password (str): Password
new_session (bool, optional): Set to True if want to get session ID of new session. Otherwise It will return the already logged In session ID. Defaults to False.
Returns:
str: Session ID.
"""
if new_session:
self.generate_session()
self.login(username, password)
if self.logged_in():
return self.session.cookies['sessionid']
raise Exception(
"You are not logged In. Set new_session=True to generate a new session.")

def get_user_id(self, username):
if isinstance(username, int) or username.isnumeric():
return username
Expand Down

0 comments on commit 4d53b44

Please sign in to comment.