Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: change the API so that it remembers the session id, we don't have to provide it each time #10

Closed
Soneji opened this issue Sep 10, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Soneji
Copy link
Contributor

Soneji commented Sep 10, 2021

Hi

I am trying to make an app using this incredible tool, however I feel some of the logic could be streamlined if the internal state of the REST API allowed for saving the session id, or at least having a mode for this. I would like to be able to:

  • login (once)
  • send request to make an instagram post with just the account username (can be many times across many days)
    • if there is an existing session, use that token to make the post
    • if there is not an existing session, return error
      • user can handle the error by sending the login request again, and then the instagram post request

The benefit of something like this is that I don't have to worry about storing any session id, which could change/become invalid at any time, within my application. I just need to store my IG user/pass, which can be used if and when the session id becomes invalid.

I feel like this could be quite easily achieved using the library "load_settings" and "dump_settings" and stored in a particular location, such as /etc/instagrapi-rest/user1.json, user2.json...

Then for Docker users (like myself), we can map that folder to a volume, ensuring that the state is maintained across container restarts. This also provides the benefit that the "device" info is maintained across container restarts too, so "Instagram can trust you more".

@Soneji Soneji added the enhancement New feature or request label Sep 10, 2021
@adw0rd
Copy link
Collaborator

adw0rd commented Sep 10, 2021

We already store the session (https://github.com/adw0rd/instagrapi-rest/blob/main/storages.py#L6), but it is assumed that this api is used for multiple accounts, in order to have access to several accounts at once, their identifier must be transmitted (now this is the sessionid, since it is most convenient to work with it)

@adw0rd
Copy link
Collaborator

adw0rd commented Sep 10, 2021

The benefit of something like this is that I don't have to worry about storing any session id, which could change/become invalid at any time, within my application. I just need to store my IG user/pass, which can be used if and when the session id becomes invalid.

I feel like this could be quite easily achieved using the library "load_settings" and "dump_settings" and stored in a particular location, such as /etc/instagrapi-rest/user1.json, user2.json...

You do not need to do load/dump, everything is already provided inside this service

@adw0rd
Copy link
Collaborator

adw0rd commented Sep 10, 2021

Then for Docker users (like myself), we can map that folder to a volume, ensuring that the state is maintained across container restarts. This also provides the benefit that the "device" info is maintained across container restarts too, so "Instagram can trust you more".

Yes, I agree, sessions are now stored in memory. After restarting the container, you will lose them and you will need to log in again. When saving to a store, I suggest doing a dump into a shared volume and reading it at startup (load_settings). Can you do it?

@Soneji
Copy link
Contributor Author

Soneji commented Sep 10, 2021

Yeah I have been playing around with this just today, and I just concluded they are stored in memory. I can try make a PR for this to update storages.py to use a file instead of in memory, is that what you think is best?

@adw0rd
Copy link
Collaborator

adw0rd commented Sep 11, 2021

@Soneji yes, thanks!

@Soneji
Copy link
Contributor Author

Soneji commented Sep 11, 2021

fab stuff, thanks :)

@Soneji Soneji closed this as completed Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants