ping / instagram_private_api

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

Example of reusing cookies for authenticated use #309

Closed andrei-polukhin closed 1 year ago

andrei-polukhin commented 3 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Which client are you using?


After reading your file on reusing cookies, I did not find clarifying information on how to use this library with cookies. Should you add some more documentation devoted specifically to this problem?

LinuxIsCool commented 3 years ago

Agreed, this information would be very helpful thank you.

321qwedsa000 commented 3 years ago

this code may help you to reuse cookie for sure.

from instagram_private_api import Client,ClientCompatPatch
import pickle
import os
def writeSettings(user,pwd,settings_file):
    api = Client(user,pwd)
    pickle.dump(api.settings,open(settings_file,"wb"))
def readSettings(settings_file):
    return pickle.load(open(settings_file,"rb"))
if not os.path.exists("settingObj"):
    writeSettings("user","pwd","settingObj")
cache_settings = readSettings("settingObj")
api = Client("user","pwd",settings=cache_settings)
andrei-polukhin commented 3 years ago

this code may help you to reuse cookie for sure.

from instagram_private_api import Client,ClientCompatPatch
import pickle
import os
def writeSettings(user,pwd,settings_file):
    api = Client(user,pwd)
    pickle.dump(api.settings,open(settings_file,"wb"))
def readSettings(settings_file):
    return pickle.load(open(settings_file,"rb"))
if not os.path.exists("settingObj"):
    writeSettings("user","pwd","settingObj")
cache_settings = readSettings("settingObj")
api = Client("user","pwd",settings=cache_settings)

Thanks!