PHP - How to get images from Instagram without API Access Token

吃可爱长大的小学妹 提交于 2019-12-04 14:14:35

问题


Can I get images from Instagram Profile without Instagram API or Access token?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/40836144/php-how-to-get-images-from-instagram-without-api-access-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!