Related Articles

Related Articles

Post a picture automatically on Instagram using Python
  • Last Updated : 16 Jul, 2020

Prerequisites: Python Programming Language

Instagram is a photo and video-sharing social networking service owned by Facebook, Python provides powerful tools for interacting with Instagram. In this article, we will come to know how we can post a picture automatically on the Instagram account just by writing a few lines of Python code.

Step 1:
Install ‘instabot‘ package using the below command in the terminal.

pip install instabot

Step 2:
Import class ‘Bot‘ from ‘instabot‘ package.

filter_none

edit
close

play_arrow

link
brightness_4
code

from instabot import Bot

chevron_right


Step 3:
Create a varibale let’s say ‘bot’ and store the class ‘Bot’ in it.



filter_none

edit
close

play_arrow

link
brightness_4
code

bot = Bot()

chevron_right


Step 4:
Login to your instagram account using the below command. Provide your Instagram ‘username’ and ‘password’.

filter_none

edit
close

play_arrow

link
brightness_4
code

bot.login(username = "******"
          password = "ppppppp")

chevron_right


Step 5:
Upload your photo using the following command.

filter_none

edit
close

play_arrow

link
brightness_4
code

bot.upload_photo("provide the path to the picture here"
           caption = "provide the caption that you \
           want to display on the post here")

chevron_right


Below is the full program to upload the photo on Instagram. The below program uploads a picture of “Techincal Scripter 2019”.

filter_none

edit
close

play_arrow

link
brightness_4
code

from instabot import Bot
  
  
bot = Bot()
  
bot.login(username = "user_name"
          password = "user_password")
  
# Recommended to put the photo
# you want to upload in the same
# directory where this Python code
# is located else you will have 
# to provide full path for the photo
bot.upload_photo("Technical-Scripter-2019.jpg",
                 caption ="Technical Scripter Event 2019")

chevron_right


Below is the screen shot of the post at Instagram of the above photo.
python-instabot

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :