ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.95k stars 612 forks source link

New solution for reusing cookies #349

Open 321qwedsa000 opened 3 years ago

321qwedsa000 commented 3 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Which client are you using?


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
TheAverageProgrammar commented 3 years ago

I have been looking for a solution for changing the user agent but have not been able to find one how to do it ?

RealA10N commented 3 years ago

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.