Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit:1, SortBy:random - always returns same image #8

Closed
fi5u opened this issue Apr 19, 2013 · 2 comments
Closed

Limit:1, SortBy:random - always returns same image #8

fi5u opened this issue Apr 19, 2013 · 2 comments
Labels

Comments

@fi5u
Copy link

fi5u commented Apr 19, 2013

Not sure if a bug or my settings:

var userFeed = new Instafeed({ get: 'user', userId: xxx, accessToken: 'xxx', template: '<div id="instaHeader" class="instaHeader" style="background-image:url({{image}});height:'+windowHeight+'px;"></div>', links: false, sortBy: 'random', limit: 1, resolution: 'standard_resolution' }); userFeed.run();

@stevenschobert
Copy link
Owner

Hey! Thanks for bringing this up. It's not really a bug, it's actually just the way Instafeed.js was built:

While the sortBy option takes is all on the client side (via Instafeed.js), the limit option actually comes from Instagram's API (that's why there's a max of 60).

The limit option sends a COUNT parameter in the API call to Instagram, so setting limit: 1 would only return 1 single image from Instagram. So then when it sorts that 1 image on the client side, you would always get the same image.


If you want to have just 1 random image, I would suggest raising the limit option, and then hiding the extra images other way. Either via CSS or some additional JavaScript.

For example you could pass a function into the after callback:

var feed = new Instafeed({
    limit: 20,
    sortBy: 'random',
    // other stuff
    after: function () {
        var images = $("#instafeed").find('a');
        $(images.slice(1, images.length)).remove();
    }
});

This will remove all the children from #instafeed except for 1.

@fi5u
Copy link
Author

fi5u commented Apr 20, 2013

Ok, I understand. Thanks for the explanation, I'll use your example in my implementation.
Tommy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants