fmchan / instagram-user-feed
这是一个用于轻松获取任何动态并交互 Instagram(点赞、关注等)的抓取器,无需 OAuth,适用于 PHP。
Requires
- php: >=7.2.5
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^6.0|^7.0
- symfony/cache: ^3.4|^4.3|^5.0|^6.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: ^8.5|^9.5
- symfony/var-dumper: ^5.0|^6.0
- dev-master
- 6.16.4
- 6.16.3
- 6.16.2
- 6.16.1
- 6.16.0
- 6.15.2
- 6.15.1
- 6.15.0
- 6.14.0
- 6.13.1
- 6.13.0
- 6.12.3
- 6.12.2
- 6.12.1
- 6.12.0
- 6.11.0
- 6.10.0
- 6.9.0
- 6.8.0
- 6.7.2
- 6.7.1
- 6.7.0
- 6.6.4
- 6.6.3
- 6.6.2
- 6.6.1
- 6.6.0
- 6.5.2
- 6.5.1
- 6.5.0
- 6.4.3
- 6.4.2
- 6.4.1
- 6.4.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.4
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.1
- 6.1.0
- 6.0.0
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.6-beta
- 5.5.3
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.1
- 5.2.0
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.1
- 5.0.0
- 4.1.0
- 4.0.0
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.0.1
- v1.0
This package is auto-updated.
Last update: 2024-09-06 18:27:15 UTC
README
警告 2022-11-09 - Instagram 再次更改了他的 DOM... 请更新到这个版本 6.16.4
警告 2022-06-01 - Instagram 更改了他的 DOM 内容和资料数据加载。请更新到这个版本 6.15.0
信息
轻松获取任何 Instagram 动态,无需 OAuth,适用于 PHP。
如果你喜欢或使用此包,请通过星级此存储库,关注 @pgrimaud 或 成为赞助者。 🙏💓
功能
- 获取用户资料数据
- 获取用户媒体
- 获取用户故事
- 获取用户精选故事
- 获取用户详细帖子
- 获取关注者动态
- 获取被关注者动态
- 关注或取消关注用户
- 点赞或取消点赞帖子
- 获取标签动态
- 获取帖子评论
- 获取直播信息
- 获取 Reels
- 获取 IGTV
- 获取被标记的用户媒体
- 获取高清头像
- 向媒体发送消息
- 新增:使用 Cookie 登录 🎉
- 新增:获取连接用户的时间线 🎉
此版本可以使用 网络抓取 获取 任何 Instagram 动态。
⚠️ 版本 ^5.0 已停止维护。 ⚠️
安装
composer require pgrimaud/instagram-user-feed
变更日志
v6.16 - 2022-08-02:
v6.15 - 2022-06-02:
- ⚠️ ⚠️ 修复资料端点。请更新到最新版本!
v6.12 - 2021-09-20:
v6.11 - 2021-09-13:
- 添加获取被标记的用户媒体的方法(示例 这里)🎉。
v6.10 - 2021-09-03:
v6.9 - 2021-09-02:
- 添加获取 Instagram 直播信息的方法。感谢 David-Kurniawan
- 小修复。
v6.8 - 2021-07-08:
- 在媒体流中添加视频 URL。感谢 @Nispeon
- 添加下载媒体的帮助器(参考 #205 : strict-origin-when-cross-origin)。感谢 @Nispeon
- 进行了一些小的修改和改进。
v6.7 - 2021-01-31:
- 新功能:获取 帖子 的 hashtag。
- 新功能:获取 帖子 的 评论。
- 支持 PHP 8。
- 进行了一些小的修改和改进。
v6.6 - 2020-10-06:
- 新功能:对帖子进行 点赞 和 取消点赞。
- 从故事中检索 hashtag 和 提及。
- 进行了一些小的修改和改进。
v6.5 - 2020-09-14:
- 新功能:关注和取消关注用户。感谢 @David-Kurniawan)
- 小修复。
v6.4 - 2020-08-30:
- 新功能:获取关注者和被关注者的动态。感谢 @David-Kurniawan)
- 进行了小的改进。
v6.3 -2020-07-03:
- 添加使用 IMAP 配置绕过检查点的挑战。
v6.2 - 2020-06-01:
- 改进媒体抓取和缓存限制。
v6.1 - 2020-05-21:
- 新功能:获取故事和精彩故事。
v6.0 - 2020-05-20
- 请从 ^5.0 升级以保持 cookies 会话稳定性。
版本 ^6.8: strict-origin-when-cross-origin
Facebook 添加了新的 CORS 策略,您无法直接显示数据。
现在您可以在您的存储或服务器上下载媒体,以直接在您的网站上提供服务。您可以在 这里 找到示例。
示例
<?php // include vendor & classes // random picture from instagram $url = 'https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-19/s150x150/156309873_1632221153646196_1273891214497323498_n.jpg?tp=1&_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_ohc=vbxGNZrjPmUAX8CIDdC&edm=ABfd0MgBAAAA&ccb=7-4&oh=ae5811c07f0e73b945eb203cd58c2101&oe=60EDD1EE&_nc_sid=7bff83' // define directory $downloadDir = __DIR__ . '/../assets'; // change it $fileName = MediaDownloadHelper::downloadMedia($url, $downloadDir); // file was downloaded here : __DIR__ . '/../assets/v-t51.2885-19-s150x150-156309873_1632221153646196_1273891214497323498_n.jpg
版本 ^6.3: 检查点挑战绕过
有些人可能在使用这个库时登录遇到困难。这通常发生在 "旧" Instagram 账户或在一些共享主机(不是所有,我不知道为什么...)上使用它时。
现在您可以使用此功能自动绕过检查点挑战。(使用代码进行电子邮件验证)。您可以在 这里 找到示例。
提示:您应该创建一个使用虚拟邮箱的虚拟 Instagram 账户来使用此功能。
它如何工作?
- 库将尝试登录
- 收到 400 错误 "checkpoint_required"
- 触发电子邮件验证
- 使用 IMAP 凭据连接到您的电子邮件收件箱
- 等待 Instagram 验证电子邮件
- 从电子邮件中解析验证码
- 使用此代码向 Instagram 发送请求以完成验证
- 验证完成,然后 自动保存会话*
*使用缓存驱动器保存会话非常重要。Instagram 会话有效期为... 1 年。所以理论上,使用缓存驱动器和单个账户只会触发一次实际的 Instagram 登录,然后长时间重用会话。
版本 ^6.0: 登录
在版本 ^6.0 中,现在登录是 强制性的,它将保存 cookies(会话)以模拟对 Instagram 的 "真实" 请求。
他们改进了机器人检测,并且没有在请求头中包含真实的会话数据,您的 IP 很容易会被 Instagram 软封。
因此,不登录就无法获取大量数据。
提示:您只需创建或使用一个虚拟账户即可轻松使用此包。
使用方法
6.0 新增 缓存:此库实现了 PSR-6 以实现最大的互操作性。
<?php use Instagram\Api; use Symfony\Component\Cache\Adapter\FilesystemAdapter; $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/../cache'); $api = new Api($cachePool); $api->login('username', 'password'); // mandatory $profile = $api->getProfile('robertdowneyjr'); echo $profile->getUserName(); // robertdowneyjr echo $profile->getFullName(); // Robert Downey Jr. Official
基本用法
<?php $api = new Api($cachePool); $api->login('username', 'password'); $profile = $api->getProfile('robertdowneyjr'); print_r($profile);
Instagram\Hydrator\Component\Feed Object ( [id] => 1518284433 [userName] => robertdowneyjr [fullName] => Robert Downey Jr. Official [biography] => @officialfootprintcoalition @coreresponse [followers] => 46382057 [following] => 50 [profilePicture] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-19/s320x320/72702032_542075739927421_3928117925747097600_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_ohc=h2zGWoshNjUAX9ze3jb&oh=cf6441cfc3f258da3bf4cfef29686c7d&oe=5EEEC338 [externalUrl] => http://coreresponse.org/covid19 [private] => [verified] => 1 [mediaCount] => 453 ( [0] => Instagram\Model\InstagramMedia Object ( [id] => 2307655221969878423 [typeName] => GraphImage [height] => 1350 [width] => 1080 [thumbnailSrc] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/c0.180.1440.1440a/s640x640/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=1b293215142d407faca46a2fd28eab71&oe=5EF0EBDF [link] => https://www.instagram.com/p/CAGcDKplv2X/ [date] => DateTime Object ( [date] => 2020-05-12 22:06:01.000000 [timezone_type] => 3 [timezone] => Europe/Paris ) [displaySrc] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=6c19ddef96fdc07d7926b05e36cb2bed&oe=5EEED2CE [caption] => The sweetest things are worth waiting for…Susan and I are producing a @Netflix original series, Sweet Tooth, based on the comic by @Jefflemire. Can’t wait to share it with you all. 🦌 👦 @NXonNetflix @warnerbrostv #SweetTooth [comments] => 3308 [likes] => 687988 [thumbnails] => Array ( [0] => stdClass Object ( [src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s150x150/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=24b300201afc0e0c82166c6288e0ed5b&oe=5EF00196 [config_width] => 150 [config_height] => 150 ) [1] => stdClass Object ( [src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s240x240/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=203d0a3d01d77a2978739c96eb67e607&oe=5EEF6DE0 [config_width] => 240 [config_height] => 240 ) [2] => stdClass Object ( [src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s320x320/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=7b9cee64460e1c9c501e59621e6ccfb2&oe=5EF18BE6 [config_width] => 320 [config_height] => 320 ) [3] => stdClass Object ( [src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s480x480/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=f3d8c31eca2d3c3ab6653b3ed3ebe4f4&oe=5EEFEAC0 [config_width] => 480 [config_height] => 480 ) [4] => stdClass Object ( [src] => https://scontent-cdt1-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/c0.180.1440.1440a/s640x640/96225997_178111910111734_5886065436455432375_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com&_nc_cat=1&_nc_ohc=GqcYpSEbz8gAX_GF1Ep&oh=1b293215142d407faca46a2fd28eab71&oe=5EF0EBDF [config_width] => 640 [config_height] => 640 ) ) [location] => [video] => [videoViewCount] => 0 ) ... [endCursor:Instagram\Model\InstagramProfile:private] => QVFEblBGclVyOEtCMmRLZkVxUUdVbmhsYXNMZmMmplNWtZRkJnRnZOSUdMM1BDRmt3ZA== )
分页
如果您想对媒体使用分页,只需调用 getMoreMedias
方法。
<?php $api = new Api($cachePool); $api->login($credentials->getLogin(), $credentials->getPassword()); $profile = $api->getProfile('twhiddleston'); print_r($profile->getMedias()); // 12 first medias do { $profile = $api->getMoreMedias($profile); print_r($profile->getMedias()); // 12 more medias // avoid 429 Rate limit from Instagram sleep(1); } while ($profile->hasMoreMedias());
故事
<?php use Instagram\Api; use Symfony\Component\Cache\Adapter\FilesystemAdapter; $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/../cache'); $api = new Api($cachePool); $api->login('username', 'password'); // mandatory $profile = $api->getProfile('starwars'); // we need instagram username sleep(1); $feedStories = $api->getStories($profile->getId()); $stories = $feedStories->getStories(); print_r($stories);
贡献者
感谢这些可爱的人们 (emoji key)
此项目遵循 all-contributors 规范。欢迎任何形式的贡献!
反馈
你发现了一个错误吗?你需要一个新功能吗?如果需要,你可以创建一个issue,或者在我的Twitter上联系我。
许可证
在MIT许可证的条款下授权。