如何在 Python 中开始使用 InstagramAPI?

How to start with the InstagramAPI in Python?

我想尝试使用 InstagramAPI 并编写一些代码,例如获取我的关注者列表之类的。我对那个话题真的很陌生。

最好的方法是什么?是否有 Python-Lib 用于处理那些 json 请求,或者我应该将它们直接发送到(新的?graphAPI,displayAPI)InstagramAPI?

感谢我能得到的每一个建议。谢谢:)

您可以使用https://github.com/LevPasha/Instagram-API-python调用Instagram APIs 如果你想直接调用 API 你可以使用 requests 包。 它还支持 graphql APIs。 在这里你可以看到一个例子: https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad

有一个库名为 instabot. This useful library has all the necessary functions/methods to interact with your insta account. Read its documentation here

pip安装为:pip install instabot

首先,假设您只想登录您的帐户。

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

要获取您的关注者列表,

my_followers = bot.followers()

如果您想上传照片或获取您的帖子,

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))

并且此库中还有许多其他 functions/methods 可用。

使用 python 与 instagram 互动实际上非常有趣。你会玩得很开心。享受:)

LevPasha 的 Instagram-API-python、instabot 和许多其他 API 自 2020 年 10 月 24 日起不再运行,因为 Facebook 弃用了旧版 API,现在有一个新的, authentication-required、API。现在需要在 Facebook 注册您的应用程序才能访问许多 API 以前无需任何身份验证即可使用的功能(通过 oembed)。

有关新实施和如何迁移的更多详细信息,请参阅 https://developers.facebook.com/docs/instagram/oembed/

您应该仍然可以通过新的 oEmbed API 和 python 获得您的关注者列表等——这将需要注册应用程序,调用新的通过 python 请求包使用您的身份验证密钥获取 API,然后处理结果。