how to login instagram programmatically

Since Instagram uses our privacy to make money, we’d better create some bots to fuck this bitch. To write an instagram bot, the first issue we’ll encounter is how to login instagram programmatically. The login process has two steps.

The first step is to visit the url[uuid] to get a csrftoken. csrftoken is returned as a cookie. In python, we can get the value of the cookie as:


Next step is to post the username/password,etc., together with the csrftoken to the following url:

postdata = json.dumps({
                    'phone_id': str(uuid.uuid4()),
                    '_csrftoken': csrftoken,
                    'username': username,
                    'guid': str(uuid.uuid4()),
                    'device_id': str(uuid.uuid4()),
                    'password': password,
                    'login_attempt_count': '0',
response =, data=postdata)

Now wet get the login cookie in the session and complete the login process. We can save the cookie in a file for later use. The uniqueness of this auto-login program is it must have the csrftoken before the real login so it requires a two-step login. Another difference than other auto-bots is the post data format. The post data must be a JSON string and contain some extra fields besides user name and password.

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!

Leave a Reply