Search code examples
imageinstagraminstagram-api

Instagram API with more than 20 images


I wanted to ask you, if there is any possibility to get more than 20 full-res images from Instagram, using the API.

<script type="text/javascript">
var feed = new Instafeed({
    get: 'user',
    userId: '2201292293',
    clientId: 'MY_CLIENT_ID',
    accessToken:`'MY_ACCESS_TOKEN',
    limit: '364',
    sortBy: 'most-liked',
    template: '<a href="{{image}}" class="popup"><img src="{{image}}"></a>{{likes}}',
    resolution: 'standard_resolution'
});
feed.run();
</script>

Solution

  • It may be caused by pagination.

    Add

    <button id="load-more">
      Load more
    </button>
    

    to your html. Every time you click on the button, feed.next() will be called and fetches more images if they exist.

    <script type="text/javascript">
        var loadButton = document.getElementById('load-more');
        var feed = new Instafeed({
            get: 'user',
            userId: '2201292293',
            clientId: 'MY_CLIENT_ID',
            accessToken:`'MY_ACCESS_TOKEN',
            limit: '364',
            sortBy: 'most-liked',
            template: '<a href="{{image}}" class="popup"><img src="{{image}}"></a>{{likes}}',
            resolution: 'standard_resolution'
    
            // every time we load more, run this function
            after: function() {
                // disable button if no more results to load
                if (!this.hasNext()) {
                    loadButton.setAttribute('disabled', 'disabled');
                }
            },
        });
    
        // bind the load more button
        loadButton.addEventListener('click', function() {
            feed.next();
        });
    
        // run our feed!
        feed.run();
    </script>
    

    Try this code.