aliparsa/instagram-php-scraper

Instagram PHP Scraper。无需授权即可获取账户信息、照片和视频


README

这个库基于Instagram网页版。我们开发它是因为现在很难获得一个经过批准的Instagram应用。目的是支持网页桌面版和移动版支持的所有功能。

依赖项

代码示例

use Phpfastcache\Helper\Psr16Adapter;

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
$instagram->login();
$account = $instagram->getAccountById(3);
echo $account->getUsername();

某些方法不需要认证

$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client());
$nonPrivateAccountMedias = $instagram->getMedias('kevin');
echo $nonPrivateAccountMedias[0]->getLink();

如果你使用认证,建议缓存用户会话。在这种情况下,你不需要每次程序运行时都执行$instagram->login()方法

use Phpfastcache\Helper\Psr16Adapter;

$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'password', new Psr16Adapter('Files'));
$instagram->login(); // will use cached session if you want to force login $instagram->login(true)
$instagram->saveSession();  //DO NOT forget this in order to save the session, otherwise have no sense
$account = $instagram->getAccountById(3);
echo $account->getUsername();

使用代理请求

// https://docs.guzzlephp.org/en/stable/request-options.html#proxy
$instagram = new \InstagramScraper\Instagram(new \GuzzleHttp\Client(['proxy' => 'tcp://:8125']));
// Request with proxy
$account = $instagram->getAccount('kevin');
\InstagramScraper\Instagram::setHttpClient(new \GuzzleHttp\Client());
// Request without proxy
$account = $instagram->getAccount('kevin');

安装

使用composer

composer.phar require raiym/instagram-php-scraper phpfastcache/phpfastcache

或者

composer require raiym/instagram-php-scraper phpfastcache/phpfastcache

如果你没有composer

你可以从这里下载这里

示例

查看示例这里

其他

Java库:https://github.com/postaddictme/instagram-java-scraper