Reputation: 305
I have an issue that my Instagram API access token keeps expiring frequently and I red the document and understood that although the token wouldn't expire generally, Instagram may decide to expire a token any time for any security reason or whatever reasons.
I know that when it expires, I need to set up an authentication process and request for a new token and all those of things. But the problem is that my app is just retrieving my own feeds to show on my own website, once the token expires it doesn't make sense to set up such a process, the only thing I can do is to manually retrieve and update the token in my code.
So I was wondering if there is still a way to get feeds without using access token as I am just pulling in my own feeds. Or is there any other way I can solve this issue?
Thanks for your help.
Upvotes: 24
Views: 42641
Reputation: 339
I've built a small SaaS that makes this dead simple: https://behold.so - it handles all the messy stuff with the new Instagram API, and just gives you a URL to a feed of posts as JSON. Like this: https://feeds.behold.so/zFgp2Jbbk23Ovf1ZUOhq
Once you have your feed URL, the code becomes trivial:
fetch('https://feeds.behold.so/zFgp2Jbbk23Ovf1ZUOhq')
.then(res => res.json())
.then(feed => {
feed.posts.forEach(({
id, // The post ID
mediaUrl, // The media source
sizes, // An object containing various image sizes
colorPalette, // An object containing extracted color values
permalink, // URL of the Instagram post
caption, // Post caption
mediaType, // 'IMAGE', 'VIDEO', or 'CAROUSEL_ALBUM'
thumbnailUrl, // Only returned for video posts
timestamp, // Post publish date,
children // An array of CAROUSEL_ALBUM children. Each with id, mediaUrl, mediaType and thumbnailUrl
}) => {
// Step 3. Make magic happen...
});
});
Apologies for the self-promotion, but the truth is there just isn't a simple way around this issue in 2022. Meta made things intentionally very difficult.
Upvotes: 3
Reputation: 396
2021 Update: Due to instagram latest changes, this is no longer a reliable solution.
Original Answer:
You can use this jquery library I developed:
https://github.com/BanNsS1/jquery.instagramFeed
No api token required
Edit for the coments below:
It's just jquery powered library that allows you to load the first 12 items of any public instagram profile.
How it solves the problem? Loading 1 to 12 last posts without requiring an access token/api key
<script type="text/javascript" src="jquery.instagramFeed.min.js"></script>
<script type="text/javascript">
(function($){
$(window).on('load', function(){
$.instagramFeed({
'username': 'instagram',
'container': "#instagram-feed1",
'display_profile': true,
'display_biography': true,
'display_gallery': true,
'get_raw_json': false,
'callback': null,
'styling': true,
'items': 8,
'items_per_row': 4,
'margin': 1
});
});
})(jQuery);
</script>
Want more? It will take 2 clicks and some scroll.
Upvotes: 6
Reputation: 351
EDIT : you can now get the json data of your profile simply with this link : https://www.instagram.com/anyuser/?__a=1
If your profile is set to public mode you can fetch your data from json response just write: https://www.instagram.com/YOURUSERNAME/media
example: https://www.instagram.com/bestcookingvideos/media
you can see json structure with : http://json.parser.online.fr/
Note: This page is not active anymore : https://www.instagram.com/YOURUSERNAME/media
2020.11.17
As in the answer you can get the profile details with 12 recent post via https://www.instagram.com/anyuser/?__a=1
but the problem is that this does not allowed to fetch media pagination. So for that you need to use
https://instagram.com/graphql/query/?query_id=17888483320059182&variables={"id":"15165085906","first":20,"after":null}
Above route will return first 20 media of the relevant user who belongs to the id and when we need get next 20 we need to pass the end_cursor
which is in initial call .
For more info ref related answer
Upvotes: 24
Reputation: 1058
https://www.instagram.com/anyuser/media
stopped working today. You can use https://www.instagram.com/anyuser/?__a=1
instead.
Upvotes: 65