How to start with the InstagramAPI in Python?

Question:

i want to play with the InstagramAPI and write some code for like getting a list of my follower and something like that. I am really new to that topic.

What is the best way to do this? Is there a Python-Lib for handle those json request or should I send them directly to the (new? graphAPI, displayAPI) InstagramAPI?

Appreciate every advice I can get. Thanks 🙂

Asked By: naheliegend

||

Answers:

You can use https://github.com/LevPasha/Instagram-API-python to call Instagram APIs
and also if you want to call API directly You can use the requests package.
It also supports graphql APIs.
Here you can see an example:
https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad

Answered By: Muhammad Azhdari

There is one library called instabot. This useful library has all the necessary functions/methods to interact with your insta account. Read its documentation here.

The pip installation is: pip install instabot

To get started with, lets say you want to simply login to your account.

from instabot import Bot
bot = Bot()
bot.login(username="YOUR USERNAME", password="YOUR PASSWORD")

To get the list of your followers,

my_followers = bot.followers()

If you want to upload a photo or get your posts,

bot.upload_photo(image, caption="blah blah blah") #the image variable here is a path to that image
all_posts = bot.get_your_medias() #this will return all of your medias of the account

#to get the info of each media, use
for post in all_posts:
    print(bot.get_media_info(post))

and there are many other functions/methods available in this library.

It actually very fun to interact with instagram using python. You will have a great time. Enjoy 🙂

Answered By: za_ali33

LevPasha’s Instagram-API-python, instabot, and many other API’s are no longer functional as of Oct 24, 2020 after Facebook deprecated the legacy API and now has a new, authentication-required, API. It now requires registering your app with Facebook to be able to get access to many of the API features (via oembed) that were previously available without any authentication.

See https://developers.facebook.com/docs/instagram/oembed/ for more details on the new implementation and how to migrate.

You should still be able to get a list of your followers, etc. via the new oEmbed API and python–it will require registering the app, making a call to the new GET API with your authentication key via the python requests package, and then processing the result.

Answered By: Fortescue

It seems like in 2022 this is the only active working and maintained python solution:
https://github.com/adw0rd/instagrapi

Answered By: NicoHood