且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP-如何在没有API访问令牌的情况下从Instagram获取图像

更新时间:2022-11-03 11:00:51

您可以获取所有图像.只需按page_info对其进行迭代.此外,还有更方便的获取json的方法:

You can get all images. Just iterate them by page_info. In addition, there is more convenient way to get json:

$otherPage = 'nasa';
$profileUrl = "https://www.instagram.com/$otherPage/?__a=1";

$iterationUrl = $profileUrl;
$tryNext = true;
$limit = 100;
$found = 0;
while ($tryNext) {
    $tryNext = false;
    $response = file_get_contents($iterationUrl);
    if ($response === false) {
        break;
    }
    $data = json_decode($response, true);
    if ($data === null) {
        break;
    }
    $media = $data['user']['media'];
    $found += count($media['nodes']);
    var_dump($media['nodes']);
    if ($media['page_info']['has_next_page'] && $found < $limit) {
        $iterationUrl = $profileUrl . '&max_id=' . $media['page_info']['end_cursor'];
        $tryNext = true;
    }
}