定制 skmachine/instagram-php-scraper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

skmachine/instagram-php-scraper

最新稳定版本:1.0

Composer 安装命令:

composer require skmachine/instagram-php-scraper

包简介

Simple Instagram PHP scraper and media proxy.

README 文档

README

Simple solution to scrape Instagram. Allows to access public Instagram data. Uses retries and high quality proxy rotation so you don't have to worry about it.

This solution uses cloud proxy service to access proxies.

Installation

Get your API key on https://rapidapi.com/neotank/api/instagram130

composer require skmachine/instagram-php-scraper

Examples of usage

See full working examples in /examples folder.

Get user profile data

<?php

require __DIR__ . '/../vendor/autoload.php';

use InstagramScraper\Client;

$client = new Client([
        // get your key on https://rapidapi.com/neotank/api/instagram130
        'rapidapi_key' => 'YOUR-RAPIDAPI-KEY' 
    ]
);

$response = $client->getAccountInfo([
    'username' => 'adele'
]);

echo '<h2>Account info for adele:</h2><pre>';
print_r($response);
echo '</pre>';

?>

Get all user media posts (paginated):

<?php
/**
 * get user posts (without reels)
 */
$response = $client->getAccountMedias([
    'userid' => '13460080',
    // 'first' => 80,
    // 'after' =>  
    // get 'after' cursor from page_info.end_cursor if page_info.has_next_page == 1
]);

Media Proxy (solving CORS issue net::ERR_BLOCKED_BY_RESPONSE)

If you want to display Instagram images on your website, you need to proxy images through your server to avoid cors error and broken images.

Example of media proxy:

put this in separate php file in web server accessible folder and call it from your other html files as mediaproxy.php?url={{INSTAGRAM_IMAGE_URL}}

require __DIR__ . '/../vendor/autoload.php';


use InstagramScraper\MediaProxy;

// use allowedReferersRegex to restrict other websites hotlinking images from your website
$proxy = new MediaProxy(['allowedReferersRegex' => "/(yourwebsite\.com|anotherallowedwebsite\.com)$/"]);

$proxy->handle($_GET, $_SERVER);

统计信息

  • 总下载量: 5.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-12-15