专用Instagram API的客户端接口。
instagram-private-api的Python项目详细描述
Instagram私有API
instagram私有api的python包装器,不依赖第三方。同时支持应用程序和Web API。
概述
我写这篇文章是为了在Instagram限制开发者访问时访问它的API。因为这意味着用official public API实现parity,所以公共api中不可用的方法通常具有较低的优先级。
有问题吗?在提交问题之前,请检查docs。
功能
- 支持许多仅通过官方应用程序提供的功能,例如:
- Web API客户端支持不需要登录的函数子集,例如:
- 获取用户info和feed
- 获取post comments
- 还有more!
- 与使用clientcompatpatch(app/web)实用程序类的公共api提供的函数兼容
- beta python 3支持
可以使用extension module帮助完成常见任务,如分页、发布照片或视频。
文档
文档可在https://instagram-private-api.readthedocs.io/en/latest/
安装
使用pip安装:
pip install git+https://git@github.com/ping/instagram_private_api.git@1.6.0
要更新:
pip install git+https://git@github.com/ping/instagram_private_api.git@1.6.0 --upgrade
要使用最新的回购代码进行更新:
pip install git+https://git@github.com/ping/instagram_private_api.git --upgrade --force-reinstall
在Python2.7和3.5上测试。
用法
app API client模拟官方应用程序,并具有一组更大的函数。web API client的集合较小,但可以在不登录的情况下使用。
您的选择将取决于您的用例。
^{
选项1:使用official app's API
frominstagram_private_apiimportClient,ClientCompatPatchuser_name='YOUR_LOGIN_USER_NAME'password='YOUR_PASSWORD'api=Client(user_name,password)results=api.feed_timeline()items=[itemforiteminresults.get('feed_items',[])ifitem.get('media_or_ad')]foriteminitems:# Manually patch the entity to match the public api as closely as possible, optional# To automatically patch entities, initialise the Client with auto_patch=TrueClientCompatPatch.media(item['media_or_ad'])print(item['media_or_ad']['code'])
选项2:使用official website's API
frominstagram_web_apiimportClient,ClientCompatPatch,ClientError,ClientLoginError# Without any authenticationweb_api=Client(auto_patch=True,drop_incompat_keys=False)user_feed_info=web_api.user_feed('329452045',count=10)forpostinuser_feed_info:print('%s from %s'%(post['link'],post['user']['username']))# Some endpoints, e.g. user_following are available only after authenticationauthed_web_api=Client(auto_patch=True,authenticate=True,username='YOUR_USERNAME',password='YOUR_PASSWORD')following=authed_web_api.user_following('123456')foruserinfollowing:print(user['username'])# Note: You can and should cache the cookie even for non-authenticated sessions.# This saves the overhead of a single http request when the Client is initialised.
避免重新登录
建议您保存/缓存身份验证cookie详细信息,以避免每次进行api调用时都登录。过度登录是一个确定的方式,使您的帐户标记为删除。还建议将客户端详细信息(如用户代理等)与身份验证详细信息一起缓存。
保存的身份验证cookie最多可重复使用90天。
捐赠
想继续这个项目吗?请慷慨解囊https://www.buymeacoffee.com/ping
支架
在提交问题报告或请求之前,请确保检查contributing documentation。
法律
免责声明:本声明不受Instagram的牵连、认可或认证。这是一个独立的非官方api。严格来说,不适用于垃圾邮件。使用风险自负。