12

I am trying to do an api call to get 10 of my posts, but it returns only 1 post, I have been using the jquery code to do the api call:

$.ajax({
  url: 'https://api.instagram.com/v1/users/6372114628/media/recent',
  dataType: 'jsonp',
  type: 'GET',
  data: {
    count: num_photos,
    access_token: accesstoken
  },
  success: function(data2) {
    for (var i = 0; i < data2.data.length; i++) {
      $(element).append('<li><a href="' + data2.data[i].link + '" target="_blank"><img src="' + data2.data[i].images.low_resolution.url + '"></a></li>');

      //$(element).append('<li><a href="'+ data2.data[i].link +'" target="_blank" style="background-image:url('+data2.data[i].images.low_resolution.url+'); background-size:cover;"></a></li>');
    }
  },
  error: function(data2) {
    $(element).append('<li>' + data2 + '</li>');
  }
});

Which returns this:

https://api.instagram.com/v1/users/6372114628/media/recent?callback=jQuery1124040077233742195983_1522982885182&count=10&access_token=6372114628.890c38a.4e03aa92b121459c84e893c54c3c0ce1&_=1522982885183

What am I doing wrong? I am only getting 1 post, I am expecting 10. I have been trying to fix this for a month now and I am not getting anywhere close. I hate this stupid thing.

I have another friend and I was able to setup her Instagram no problem:

https://api.instagram.com/v1/users/1960989467/media/recent?access_token=1960989467.1677ed0.6ab08c98b04c4b5bac6410ed045a6dbc&count=9&callback=instafeedCache35472b641655efc8.parse

Returns 9 items as expected. This makes no sense what so ever. How is one working and the other is not?

Sincerely, A very frustrated developer.

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
user979331
  • 11,039
  • 73
  • 223
  • 418

5 Answers5

5

I have exactly the same issue as you. For some accounts unfortunately they do not return full list of images. If you add new image to given account most probably it will appear in Instagram API.

What I believe it is a bug on Instagram old API. Unfortunately it is not possible to notify Instagram developers about this bug, as bug report program for old API is closed. They accept tickets only for new Graph API.

IMHO it is nothing you can do at this point. It does not matter which plugin you are using. It is broken for some of the Instagram accounts. As old Instagram API will be deprecated soon, I would suggest slowly moving to new Graph API. Old API was buggy recently. I'm using it a lot and I had such situation few times. Newly added images are appearing in responses from API, however it is not possible to fetch older images.

Krystian
  • 996
  • 9
  • 24
  • So all I have to do is add new posts? Is that what you are saying? – user979331 Apr 06 '18 at 13:59
  • Or do I have to do this? https://developers.facebook.com/docs/instagram-api/getting-started/ – user979331 Apr 06 '18 at 14:45
  • Hey, so do I just follow these steps here? https://developers.facebook.com/docs/instagram-api/getting-started/ – user979331 Apr 09 '18 at 12:55
  • @user979331 You can start add new posts and they should appear in Instagram API. If you plan to use Instagram API long term you should start thinking about moving to new Graph API on Facebook. However please keep in mind that currently Graph API works only for Instagram Business accounts – Krystian Apr 10 '18 at 06:24
  • Same problem here. No answer as yet. Its just broken currently. Sandbox api seems to work correctly though. – SpeedOfSpin Apr 11 '18 at 16:28
3

element='.feed';

$.ajax({
url: 'https://api.instagram.com/v1/users/6372114628/media/recent?callback=jQuery1124040077233742195983_1522982885182&count=10&access_token=6372114628.890c38a.4e03aa92b121459c84e893c54c3c0ce1&_=1522982885183',
dataType: 'jsonp',
type: 'GET',
data: {},
success: function(data2) {
 console.log(data2.data.length);
 for(var i = 0; i < data2.data.length; i++) {
  $(element).append('<li><a href="'+ data2.data[i].link +'" target="_blank"><img src="'+data2.data[i].images.low_resolution.url+'"></a></li>');
  //$(element).append('<li><a href="'+ data2.data[i].link +'" target="_blank" style="background-image:url('+data2.data[i].images.low_resolution.url+'); background-size:cover;"></a></li>');
 }
},
error: function(data2) {
 $(element).append('<li>'+ data2 +'</li>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="feed"></div>

I got three results, you can think of why these three pictures go through but others don't.

Omar Himada
  • 2,540
  • 1
  • 14
  • 31
Wils
  • 1,178
  • 8
  • 24
2

It seems there is an API problem because it just gives you 5 posts of that intended account. you should use their new GraphQl API SDKs.

check this https://developers.facebook.com/docs/instagram-api

Madmadi
  • 2,064
  • 1
  • 14
  • 17
1

Try plugin calls "instafeed.js". It is very easy to use.

http://instafeedjs.com/.

Example :
You have to specify userId and accessToken or client_id.

var feed = new Instafeed({
                        get: 'user',
                        tagName: 'instafeed',
                        userId: userid,
                        accessToken: key,
                        resolution: 'standard_resolution',
                        target: 'feed-images', // Id of `enter code here`
                        limit: 10,
                        template: '<li><a class="fancybox" rel="gallery1" href="\{\{image\}\}"><img src="\{\{image\}\}" /></a></li>',
                        after: function () {
                            // Effect like slider of fanvybox
                        },
                        error: function (error) {
                            console.log(error);
                        }
                    });
                    feed.run();
Nirali
  • 1,776
  • 2
  • 12
  • 23
1

Dude, the access token you use to fetch the photos, it only gives 5 photos, I think you've to re-check Instagram developer section to see everything is correct or you mistakenly put some limitation on photos. Cause there's only 5 id's are there.
So, the solution either re-check the sandbox setting and everything OR delete this and create a new one. Don't frustrate on that one. Cause whatever you do, you only get 5 but I also checked your friend's API, it generates more than 5, that's why she gets more than 5 photos. Just re-check OR Create a new one.
Here's the jquery code to check,

var reviews = document.querySelector("put your selector here"),
    access_id = "6372114628.890c38a.4e03aa92b121459c84e893c54c3c0ce1",
    post_count = 10;
var query = jQuery.ajax({
    url: `https://api.instagram.com/v1/users/self/media/recent?access_token=${access_id}&count=${post_count}&callback=?`,
    error: function () {
        console.error();
    },
    success: function (result) {
        result.data.map(function (item) {
            reviews.innerHTML += `<a class="images" href="${item.link}" target="_blank"><img src="${item.images.low_resolution.url}" /></a>`;
        });
    },
    type: "GET",
    dataType: "jsonp"
});
Pranab
  • 305
  • 3
  • 13