softcoder24 / insta_share

Share a post into your Instagram account using the requests library.
Other
27 stars 10 forks source link

Login problem fix #9

Open oluca opened 2 years ago

oluca commented 2 years ago

Hey guys,

i have the problem that i cant login through login() and following code fixed it for me:


def login(self, username: str, password: str) -> dict:
        url = 'https://www.instagram.com/data/shared_data/'
        login_url = 'https://www.instagram.com/accounts/login/ajax/'

        time = int(datetime.now().timestamp())

        session = requests.Session()
        response = session.get(url)
        csrf = json.loads(response.text)['config']['csrf_token']
Dymirt commented 1 year ago

There is no 'csrf_token' now in response, because instagram change login page and 'csrf_token' is generated dynamically in JavaScript 'window._sharedData'. So to get this token you can use Selenium