使用Instagram Basic Display API获取用户媒体

问题描述 投票:1回答:1

我想使用Instagram Display 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(来源https://stackoverflow.com/a/33783840/12739212)的方法,但我担心他们会更改其代码,因此此解决方案将不再起作用,因此我想使用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 . ">";
        }

提前感谢。

instagram instagram-api instagram-graph-api
1个回答
0
投票

您好,我在link中找到了本教程,但麻烦很多,我宁愿不断更改代码,而不愿意做这些事情

© www.soinside.com 2019 - 2024. All rights reserved.