如何在Python中使用InstagramAPI?

2024-09-27 02:20:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想玩InstagramAPI并编写一些代码,比如获取我的追随者列表之类的东西。我对那个话题真的很陌生

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

谢谢你给我的每一个建议。谢谢:)


Tags: 方法代码json列表建议话题graphapiinstagramapi
3条回答

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

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

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

您可以使用https://github.com/LevPasha/Instagram-API-python调用Instagram API 而且,如果您想直接调用API,也可以使用requests包。 它还支持GraphQLAPI。 这里您可以看到一个示例: https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad

有一个名为instabot的库。此实用库具有与insta帐户交互所需的所有功能/方法。阅读其文档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))

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

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

相关问题 更多 >

    热门问题