orsifrancesco / instagram-without-api
一段简单的PHP代码,用于获取无限的Instagram公共图片(用户和标签),无需API,无需凭据(只需从cookies中的token),只需Instagram抓取(带有cookie和base64中的图像数据)。
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
This package is not auto-updated.
Last update: 2024-09-24 22:55:25 UTC
README
Instagram已将图片数组移动到另一个端点(涉及多个重定向),这使得在没有像Puppeter这样的抓取器的情况下从服务器端捕获图像变得更加困难。
也许将来我会分享一个新版本,但鉴于社区中许多无感激和合作的需求,我已经失去了兴趣。
无需API的Instagram
2023年4月无需凭据的Instagram抓取 (@users 和 #tags)
这是一个PHP库,你在寻找Node.js版本吗?请访问 https://orsi.me/instagram-without-api/。
一段简单的PHP代码,通过每个用户的 无限Instagram公共图片 无需API,无需凭据(只需从cookies中的token),只需2023年的Instagram抓取(带有cookie和base64中的图像数据)。
您可以通过id获取账户或单个图片的最新图片/信息。
📦 Packagist链接
🛕 令人兴奋的项目示例 
🎮 示例
⚖️ MIT许可
🤓 作者 @orsifrancesco
☕ 欢迎捐赠咖啡(特别是如果您喜欢这个项目或打算联系我)
📦 从 Composer仓库 安装
composer require orsifrancesco/instagram-without-api
📦 从此仓库安装
composer install # download the file https://github.com/orsifrancesco/instagram-without-api/blob/master/test.php # add your cookie, user-agent and x-ig-app-id following the next step "How to get Instagram Cookie" php test.php
🍪 如何获取Instagram Cookie
- 登录Instagram
- 访问您的 https://instagram/yourUsername
- 打开浏览器控制台(在Chrome中按F12)
- 选择“网络”标签
- 搜索并单击“timeline/”文件;如果它是空的,请刷新页面
- 选择“Headers”栏
- 确保该文件是请求方法“POST”(如果是“OPTIONS”,则在列表中搜索其他“timeline/”文件)
- 向下滚动并选择“Request Headers”标签
- 复制“cookie:”之后的所有代码,并将其粘贴到
$cookie
变量中 - 复制“user-agent:”之后的所有代码,并将其粘贴到
$userAgent
变量中 - 复制“x-ig-app-id:”之后的所有代码,并将其粘贴到
$xIgAppId
变量中
- don't share your cookie code with anyone!!! it is the same of your credentials
- 完成,祝您玩得开心 :)
💻 Base64图像
尽管您可以获取图像的URL,但Instagram不提供将图像包含并在您的项目中显示这些图像的可能性(它们将自动被其服务器阻止)。
要解决这个问题,您将获取所有URL和所有图像数据的base64。
您可以使用以下代码片段轻松地在项目中显示图像数据
<img src="data:image/jpg;base64, hereYourBase64String.."/>
.example { background-image: url('data:image/jpg;base64, hereYourBase64String..'); }
查看https://orsifrancesco.github.io/instagram-without-api/how-to-show-base64-images.html获取Base64示例。
🛕 精彩项目示例
🎮 示例
在https://github.com/orsifrancesco/instagram-without-api/blob/master/test.php上的示例
<?php require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload use InstagramWithoutApi\Fetch; $cookie = 'mid=YYcwjgAL....8765"'; // <!-- required!! please get your cookie from your browser console (6) $userAgent = 'Mozilla/5.0...Chrome/537.36'; // <!-- required!! please get your user-agent from your browser console (7) $xIgAppId = '9366197...'; // <!-- required!! please get your x-ig-app-id from your browser console (8) // get the latest 12 feeds from a tag (example https://instagram.com/explore/tags/love) echo Fetch::fetchByTag([ "group" => 'recent', // <!-- "recent" images or "top" images; "recent" is by default "base64images" => true, // <!-- optional, but without you will be not able to save images.. it increases the size of the json file "base64imagesCarousel" => false, // <!-- optional but not recommended, it increases the size of the json file "base64videos" => false, // <!-- optional but not recommended, it increases the size of the json file "header" => 'cookie: ' . $cookie . "\r\n" . 'user-agent: ' . $userAgent . "\r\n" . 'x-ig-app-id: ' . $xIgAppId . "\r\n" . '', "maxImages" => 4, // <!-- optional, 12 is the max number "file" => "instagram-cache-bytag.json", // <!-- optional, instagram-cache.json is by default "time" => 3600, // <!-- optional, reload contents after 3600 seconds by default "pretty" => true, // <!-- optional, prettyfy json true/false "id" => "love", // <!-- id is required ]); // get the latest 12 pictures from an account (example https://www.instagram.com/orsifrancesco/) echo Fetch::fetch([ "base64images" => true, // <!-- optional, but without you will be not able to save images.. it increases the size of the json file "base64imagesCarousel" => false, // <!-- optional but not recommended, it increases the size of the json file "base64videos" => false, // <!-- optional but not recommended, it increases the size of the json file "header" => 'cookie: ' . $cookie . "\r\n" . 'user-agent: ' . $userAgent . "\r\n" . 'x-ig-app-id: ' . $xIgAppId . "\r\n" . '', "maxImages" => 4, // <!-- optional, 12 is the max number "file" => "instagram-cache.json", // <!-- optional, instagram-cache.json is by default "time" => 3600, // <!-- optional, reload contents after 3600 seconds by default "pretty" => true, // <!-- optional, prettyfy json true/false "id" => "orsifrancesco", // <!-- id is required ]); // get picture and info from instagram id url (example https://www.instagram.com/p/Cgczi6qMuh1/) echo Fetch::fetchByIdUrl([ "header" => 'cookie: ' . $cookie . "\r\n" . 'user-agent: ' . $userAgent . "\r\n" . 'x-ig-app-id: ' . $xIgAppId . "\r\n" . '', "file" => "instagram-cache-byidurl.json", // <!-- optional, instagram-cache-byidurl-{id}.json is by default "time" => 3600, // <!-- optional, reload contents after 3600 seconds by default "pretty" => true, // <!-- optional, prettyfy json true/false "id" => "Cgczi6qMuh1", // <!-- id is required ]); // get picture and info from instagram id (2898553675947377985 is the id of https://www.instagram.com/p/Cgczi6qMuh1/) echo Fetch::fetchById([ "base64images" => true, // <!-- optional, but without you will be not able to save images.. it increases the size of the json file "base64videos" => false, // <!-- optional but not recommended, it increases the size of the json file "header" => 'cookie: ' . $cookie . "\r\n" . 'user-agent: ' . $userAgent . "\r\n" . 'x-ig-app-id: ' . $xIgAppId . "\r\n" . '', "file" => "instagram-cache-byid.json", // <!-- optional, instagram-cache-byid-{id}.json is by default "time" => 3600, // <!-- optional, reload contents after 3600 seconds by default "pretty" => true, // <!-- optional, prettyfy json true/false "id" => "2890411760684296309", // <!-- id is required ]); ?>
🕹️ JSON 输出
在https://github.com/orsifrancesco/instagram-without-api/blob/master/instagram-cache.json上的Fetch::fetchByTag
或Fetch::fetch
输出示例
[ { "id": "2696840872190940431", "time": 1635708506, "imageUrl": "https://scontent-lcy1-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/249938862_1214260935751176_32...", "likes": 18, "comments": 0, "link": "https://www.instagram.com/p/CVtGnwashUP/", "text": "#helloworld #domain #check", "image": "/9j/4AAQSkZJRgABAQAAAQABAAD/7QB8UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAGA.............", "location": "Liverpool Cathedral", "carousel": [ { "imageUrl": "https://scontent.cdninstagram.com/v/t51.2885-15/314902884_370847155226583_8126....", "image": "/9j/4AAQSsasaakZJRgABAQAAAQABAAD/7QB8UGhvdGQAAAAAAGA............." }, { "imageUrl": "https://scontent.cdninstagram.com/v/t51.2885-15/314674373_678631710324...", "image": "/9j/4AAQSkZJRgABAQAAAQdG9zaG9wIDMuMAA4QklNBAQAAAAAAGA............." } ] }, { "id": "2654027113529608497", "time": 1630604708, "imageUrl": "https://scontent-lcy1-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/241221239_8640769...", "videoUrl": "https://scontent-lcy1-1.cdninstagram.com/v/t51.2885-15/e35/p1080x1080/241221239_8640769...", "likes": 38, "comments": 0, "link": "https://www.instagram.com/p/CTU_5keMAkx/", "text": "#london #uk #unitedkingdom #tube #underground #overground #sunrise #morning #morningvibes #sky #metro #line #prospective", "image": "/9j/4AAQSkZJRgABAQAAAQABAAD/7QB8UGhvdG9zaG9wIDMuMAA4Qkl...........", "location": "Eiffle Tower, Paris France." } ]
Fetch::fetchByIdUrl
或Fetch::fetchById
的输出示例
[ { "id": "289855367...", "width": 1385, "height": 1731, "imageUrl": "https:\/\/scontent-lhr8-1.cdnin...", "time": 1659754546, "topLikers": [ "franko" ], "likes": 32, "commentCount": 2, "comments": [ { "time": 1659756069, "text": "This is a comment...", "user": { "username": "test", "fullName": "DearTest", "imageUrl": "https:\/\/scontent-lhr8-1.cdninstagram.com..." } } ], "link": "https:\/\/www.instagram.com\/p\/Cgczi6qMuh1\/", "text": "If you know it, you know it...", "user": { "username": "orsifrancesco", "fullName": "Frank", "imageUrl": "https:\/\/scontent-lhr8-1.cd..." }, "image": "\/9j\/4AAQSkZJR....Q==" } ]
⚖️ 许可证
基于MIT许可
☕ 关于
欢迎对@orsifrancesco和咖啡提供反馈 :)