Search code examples
javascriptjqueryinstagraminstagram-api

Instagram api count not working


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.


Solution

  • 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();