问题
i want to show public contents from instagram related to a specific hashtag (everything works fine with that) but i can't to renew the access_token
everytime it expires.
("do not assume your access_token is valid forever." - https://www.instagram.com/developer/authentication/)
To renew it manually is not an option i have to make sure there is a valid access_token
at ANY time without re-authenticating.
Any ideas or questions? :)
回答1:
I have one idea, but without API (and access_token
). You can make requests to the web-version of Instagram with ?__a=1
parameter. I do not know how long it will work but now there is workflow:
- You want to show public content with hashtag
space
, for example. - Add it to url and add GET-parameter
?__a=1
: https://www.instagram.com/explore/tags/space/?__a=1 - Make the GET-request. It returns
json
with nodes intop_posts
(8) andmedia
(18). Each node hasowner
,caption
, number of comments and likes. But the most important part is inthumbnail_src
anddisplay_src
. - There is
page_info
inmedia
object which helps to paginate results. You needend_cursor
(for example,J0HWE9rjAAAAF0HWE9qvgAAAFiYA
) - Add the value from
end_cursor
to the url: https://www.instagram.com/explore/tags/space/?__a=1&max_id=J0HWE9rjAAAAF0HWE9qvgAAAFiYA - Repeat 3-6 to get newest posts with specific hashtag.
回答2:
Update to the ?__a=1 url param. This appears to have stopped working with users '/account/?__a=1' endpoints.:( Still works on tags apparently.
回答3:
Instagram shut down their public API. Here's a quick and dirty workaround in PHP:
<?php
function getPublicInfo($username) {
$url = sprintf("https://www.instagram.com/$username");
$content = file_get_contents($url);
$content = explode("window._sharedData = ", $content)[1];
$content = explode(";</script>", $content)[0];
$data = json_decode($content, true);
return $data['entry_data']['ProfilePage'][0];
}
Not sure for how long it's gonna work. Here's one for Javascript.
来源:https://stackoverflow.com/questions/40990940/accessing-public-instagram-content-via-instagram-api-without-expiring-accesstoke