PHP-如何在没有API访问令牌的情况下从Instagram获取图像 [英] PHP - How to get images from Instagram without API Access Token

查看:97
本文介绍了PHP-如何在没有API访问令牌的情况下从Instagram获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从没有Instagram API或Access令牌的Instagram个人资料中获取图像吗?

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

推荐答案

您可以获取所有图像.只需按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;
    }
}

这篇关于PHP-如何在没有API访问令牌的情况下从Instagram获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆