如何从 Python 中的 InstagramAPI 开始?

nah*_*end 2 python instagram instagram-graph-api

我想使用 InstagramAPI 并编写一些代码来获取我的关注者列表之类的东西。我对这个话题真的很陌生。

做这个的最好方式是什么?是否有用于处理这些 json 请求的 Python 库,还是应该将它们直接发送到(新的?graphAPI、displayAPI)InstagramAPI?

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

za_*_*i33 6

有一个名为instabot 的库。这个有用的库拥有与您的 insta 帐户交互所需的所有功能/方法。请在此处阅读其文档。

pip安装是:pip install instabot

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

from instabot import Bot
bot = Bot()
bot.login(username="YOUR USERNAME", password="YOUR PASSWORD")
Run Code Online (Sandbox Code Playgroud)

要获取您的关注者列表,

my_followers = bot.followers()
Run Code Online (Sandbox Code Playgroud)

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

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))
Run Code Online (Sandbox Code Playgroud)

该库中还有许多其他可用的函数/方法。

使用 python 与 Instagram 交互实际上非常有趣。你会度过一段愉快的时光。享受 :)

  • 不幸的是 InstaBot 不再维护,他们自己建议不要使用它 (4认同)
  • 将您的登录凭据传递给第三方对我来说听起来有点奇怪 (2认同)

小智 6

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

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

您仍然应该能够通过新的 oEmbed API 和 python 获取您的关注者列表等——它需要注册应用程序,通过 python requests 包使用您的身份验证密钥调用新的 GET API,以及然后处理结果。