instagram_private_api
instagram_private_api copied to clipboard
New solution for reusing cookies
Please follow the guide below
- Issues submitted without this template format will be ignored.
- Read the questions carefully and answer completely.
- Do not post screenshots of error messages or code.
- Put an
xinto all the boxes [ ] relevant to your issue (==> [x] no spaces). - Use the Preview tab to see how your issue will actually look like.
- Issues about reverse engineering is out of scope and will be closed without response.
- Any mention of spam-like actions or spam-related tools/libs/etc is strictly not allowed.
Before submitting an issue, make sure you have:
- [x] Updated to the lastest version v1.6.0
- [x] Read the README and docs
- [x] Searched the bugtracker for similar issues including closed ones
- [x] Reviewed the sample code in tests and examples
Which client are you using?
- [x] app (
instagram_private_api/) - [ ] web (
instagram_web_api/)
Describe your Feature Request:
Please make sure the description is worded well enough to be understood with as much context and examples as possible.
#simple solution for reusing cookies
from instagram_private_api import Client
import pickle
import os
#write binary file with api.settings
def writeSettings(user,pwd,settings_file):
api = Client(user,pwd)
with open(settings_file,"wb") as FileObj:
pickle.dump(api.settings,FileObj)
#read binary file to api.settings
def readSettings(settings_file):
cache = None
with open(settings_file,"rb") as FileObj:
cache = pickle.load(FileObj)
return cache
if not os.path.exists("settingObj"):
writeSettings("user","pwd","settingObj")
cache_settings = readSettings("settingObj")
api = Client("user","pwd",settings=cache_settings)
#usually worked well
I have been looking for a solution for changing the user agent but have not been able to find one how to do it ?
Be careful, you are opening files without closing them. The best practice is to open files using the with open(...) as ... syntax,
In any case, the developer of the module intentionally left the implementation of caching the settings to the user of the library.