我想使用 Instagram Display API 从帐户检索照片,但在文档中找不到任何内容。
最接近的是这个https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media?locale=en_US 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 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 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 . ">";
}
提前致谢。