使用Instagram Basic Display API获取用户媒体 [英] Getting User Media with Instagram Basic Display API
问题描述
我想使用Instagram Display API从一个帐户中检索照片,但是我在文档中找不到任何内容.
I would like to retrieve photos from an account with the Instagram Display API but I can't find anything on the documentation.
与之最接近的是这个 https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media?locale=zh_CN ,但它仅允许您恢复连接到API的人的照片.但是,我希望能够从他们的用户名或主题标签中恢复任何人的照片.
The closest thing to that is this https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media?locale=en_US but it only allows you to recover photos of the person connected to the API. However, I would like to be able to recover photos of anyone from their username, or from a hashtag.
GET /me?fields={media}&access_token={access-token}
我还发现了这个 https://developers.facebook.com/docs/instagram-basic-display-api/reference/user/media ,但在何处没有解释如何从用户名获取某人的用户ID.
I also found this https://developers.facebook.com/docs/instagram-basic-display-api/reference/user/media but it is nowhere explained how to get someone's user-id from a username.
GET https://graph.instagram.com/{user-id}/media?access_token={access-token}
我找到了一种无需Instagram API的方法(来源 https://stackoverflow.com/a/33783840/12739212),但恐怕他们会更改其代码,因此该解决方案将不再起作用,因此我想使用Instagram API
I find a way to do it without Instagram API (Sources https://stackoverflow.com/a/33783840/12739212) but I'm afraid they will change their code and therefore this solution will no longer work so I would like to do it with the 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 . ">";
}
谢谢.
推荐答案
So I finally gave up using the API and used this library instead https://github.com/postaddictme/instagram-php-scraper
这篇关于使用Instagram Basic Display API获取用户媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!