mikefowler / instajam

Instajam is a JavaScript wrapper for the Instagram API. You provide the access token, we provide the jam. Or whatever.
http://mikefowler.github.io/instajam
MIT License
132 stars 33 forks source link

Pagination #10

Open dseeker opened 9 years ago

dseeker commented 9 years ago

Is there a way to use pagination?

I'm trying to get all users who liked an item of media, is it just undocumented or not possible?

theirnameissam commented 9 years ago

This could help you out: https://github.com/stevenschobert/instafeed.js

VojtaSim commented 8 years ago

You can use instagram's native method to paginate by passing options object before callback function.

Example:

function loadUserMedia()  {
    API.user.self.media({ count: 13 }, function (response) {
        parseMedia(response);
    });
}

function parseMedia (response) {
    if (response.meta.code !== 200) 
        error(response);

    if (response.data.length == 0) 
        return;

    var lastMediaID, loadMoreBtn = $(/**  **/);

    for (var i = 0, media; media = response.data[i]; i++) {
        lastMedia = media.id;
        if (media.type == "video") continue;  // remove if you want videos

        // do your own stuff
        images.add(/** **/);
    }

    if (response.pagination && response.pagination.next_max_id !== undefined) {
        loadMoreBtn.removeClass('hidden');

        loadMoreBtn.off('click').on('click.instagram.user.loadMore', function (e) {
            e.preventDefault();

            $(this).addClass('loading');

            API.user.self.media({ count: 13, max_id: lastMedia }, function (response) {
                parseMedia(response);
            });
        });
    }
}