使用 Instagram 基本显示获取用户媒体 API

Getting User Media with Instagram Basic Display API

我想从 Instagram 显示帐户中检索照片 API 但我在文档中找不到任何内容。

最接近的是 https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media?locale=en_US,但它只允许您恢复与 API 相关联的人的照片。但是,我希望能够从用户名或主题标签中恢复任何人的照片。

GET /me?fields={media}&access_token={access-token}

我也找到了这个 https://developers.facebook.com/docs/instagram-basic-display-api/reference/user/media 但是没有任何地方解释如何从用户名中获取某人的用户 ID。

GET https://graph.instagram.com/{user-id}/media?access_token={access-token}

我找到了一种不用 Instagram API(来源 )的方法,但我担心他们会更改代码,因此这个解决方案将不再有效,所以我想使用 Instagram API

        $html = file_get_contents('https://instagram.com/' . $username . '/');
        preg_match('/_sharedData = ({.*);<\/script>/', $html, $matches);
        $profil_data = json_decode($matches[1])->entry_data->ProfilePage[0]->graphql->user;
        $data_edges = $profil_data->edge_owner_to_timeline_media->edges;

        foreach ($data_edges as $key => $value) {
            $img_url = $value->node->display_url;
            echo "<img src=" . $img_url . ">";
        }

提前致谢。

你好,我在这个 link 中找到了这个教程,但它很麻烦,我宁愿继续更改代码,也不愿继续做这些事情

所以我最终放弃了使用 API 而使用了这个库 https://github.com/postaddictme/instagram-php-scraper