获取所有用户媒体 - Instagram

Get all user medias - Instagram

我可以使用下面的代码通过 public API 获取 Instagram 照片(如 How to get all images of hashtag in Instagram without API? 中所示)

<?php

$baseUrl = 'https://www.instagram.com/explore/tags/girls/?__a=1';
$url = $baseUrl;

while(1) {
    $json = json_decode(file_get_contents($url));
    print_r($json->tag->media->nodes);
    if(!$json->tag->media->page_info->has_next_page) break;
    $url = $baseUrl.'&max_id='.$json->tag->media->page_info->end_cursor;
}

然而,此代码仅返回给我 95 个媒体,即使用户有 1000+ 个媒体(任何用户)

有什么问题吗?

谢谢

你为什么不使用 instagram-php-scraper

您可以通过 composer 安装它。在您的服务器上创建一个新目录并在您的控制台上键入以下内容:

composer require raiym/instagram-php-scraper

然后只需使用:

<?php
require 'vendor/autoload.php';
use InstagramScraper\Instagram;
$medias = Instagram::getMediasByTag('pedro', 200);
header('Content-Type: application/json');
echo json_encode($medias);

检查所有可用的方法:

https://github.com/postaddictme/instagram-php-scraper/blob/master/README.md