23

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.

Ryan
  • 233
  • 1
  • 2
  • 4
  • 1
    There is that PHP project that uses Instagram inner API. It can do most functions the site can. It does not need an access token, it uses your username and password: https://github.com/mgp25/Instagram-API – caffeinum Jun 16 '18 at 23:16

4 Answers4

66

https://www.instagram.com/anyuser/media stopped working today. You can use https://www.instagram.com/anyuser/?__a=1 instead.

adiga
  • 34,372
  • 9
  • 61
  • 83
John Codeos
  • 1,060
  • 1
  • 13
  • 17
  • 1
    Do you know how to get the next page using ?__a=1 method? There is page_info.end_cursor in the returned JSON, but it is unclear how to use it. – Vladimir Lebedev Nov 10 '17 at 08:56
  • 3
    @VladimirLebedev use the max_id parameter, such as https://www.instagram.com/anyuser/?__a=1&max_id=[Last id on previous call] – paranoidhominid Nov 15 '17 at 02:40
  • Is there any rate limit for this? and also it is returning only 12 posts each page, any idea how to increase the posts per page? – KabirB Nov 28 '17 at 12:30
  • This is very interesting. Is there any description of all parameters and why is it working without API key? Or maybe info if it is intended to work so or it is just some glitch. – rackom Dec 14 '17 at 14:30
  • json schema of `https://www.instagram.com/anyuser/?__a=1` has been changed – John Codeos Mar 15 '18 at 15:58
  • 3
    https://www.instagram.com/anyuser/?__a=1 Its no more accessible. is there anything else ? – Rakesh Bhatt Apr 13 '18 at 09:03
  • 3
    Yeah, it seems they took it down after the Facebook analytica thing. – John Codeos Apr 13 '18 at 12:24
  • Since this URL "instagram.com/anyuser/?__a=1" is no more working now.. Did you guys find any alternate solution? – Rupali Apr 19 '18 at 08:36
  • 1
    @KarimHaddad if that fits you, there is a PHP library that connects via user/pass https://github.com/mgp25/Instagram-API – caffeinum Jun 16 '18 at 23:17
  • As an alternative solution, you can use this PHP [library](https://github.com/pgrimaud/instagram-user-feed) in version 5 which uses scrapping to retrieve informations. – sasensi Dec 20 '18 at 09:03
23

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 .

enter image description here

For more info ref related answer

Nipun Tharuksha
  • 2,496
  • 4
  • 17
  • 40
  • 1
    @Dimitrije Zoroski, Do you know how I can iterate to get more post? or if it's possible to ask for more than 20 posts? – Carolina Jan 10 '17 at 14:13
  • 1
    @Carol Yes. you can! With link : https://www.instagram.com/bestcookingvideos/media/?max_id=LastIdOfItem Where LastIdOfItem is id of your last item in json text, id is something like this. "id":"1394603188540132178_3272768483". – Dimitrije Zoroski Jan 17 '17 at 20:15
  • Confirmed working as at 19/10/2017. Although I'm pretty sure this is not a supported API. – Mark Oct 19 '17 at 05:44
  • 8
    Was this feature just discontinued? – developernaren Nov 08 '17 at 06:57
7

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.

Javier S
  • 379
  • 3
  • 13
  • can we get our own feeds(stories from people we follow) using this method? – user1788736 Jul 07 '19 at 00:07
  • Not yet, I'll take a look soon – Javier S Jul 08 '19 at 06:12
  • jquery.instagramFeed no longer works in 2021, infortunately.. if someone still needs Instagram feed on their website - take a look at https://github.com/restyler/inwidget-proxified as a server-side alternative. –  May 11 '21 at 10:01
0

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/xN3J7TZ59jIdH6IOWQ4d')
  .then(data => data.json())
  .then(photos => {
    photos.forEach(({
      id,             // The post ID
      mediaUrl,       // The image source
      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.

Griffin
  • 196
  • 2
  • 8
  • 1
    What proxies do you use? – DarkestOne May 17 '22 at 14:59
  • No proxies, this isn't a scraper. It uses the (incredibly annoying) official APIs. – Griffin May 19 '22 at 14:21
  • Good service but requires access token from the page owner which complicates things. It should be simple enough to build your own feed fetcher API using Instagram's private API. – Konrad Feb 10 '23 at 21:55
  • You can definitely build your own. As with everything like this, it's all about cost/benefit given the value of your time and the size of a project. Instagram's two APIs come with some gotchas and are frankly a little buggy. Access tokens also require regular refreshing, so at minimum you need to set up a service/cron job that does that. Part of the value of something like Behold is that we handle those complexities behind the scenes. By no means is it the only way, however. – Griffin Feb 12 '23 at 17:50