stevenschobert/instafeed.js

How to sort instafeed with a function

zackwwww opened this issue · 3 comments

I've recently updated a website that uses the Instafeed.js plugin from the old version to the new one. In the new version, the 'sortBy' option has been replaced by a 'sort' option, and as I've read on GitHub, it now 'uses a function' instead of the simple strings as in the previous version.

My Javascript knowledge is basic, and I've not come across something like this in a js plugin before. I don't really understand how I can write a function to sort the posts from the feed by the number of likes from most liked to least liked, since I can't see where the number of likes is made available from the Instagram API.

If anyone could point me in the right direction it would be really appreciated.

Hi
FB does not allow to get a number of likes, only in business account, in API

20th June 2020: New Basic Display API
To achieve this, the launching of Instagram Basic Display API comes with 3 major changes:

  • To protect users’ privacy, location information will no longer be included along with the media;
  • Only Instagram business accounts will continue to support likes and comments on the hover overlay;
  • The number of data fields like location data and follower counts are going to be censored.

font: https://embedsocial.com/blog/instagram-api-changes-2020/

thanks v much. should have checked that...

Hey @zackwwww! Like @vulkanus said, the new Instagram Basic Display API that powers v2 of Instafeed.js does not include like counts, unfortunately, which is partly why the sortBy option was dropped in favor of sort.

To answer the other half of your question though, the sort option works exactly like the Array.prototype.sort() standard library function. You can find examples of how to write a sort function on the MDN docs site.

The basic structure is:

function compare(a, b) {
  if (a is less than b by some ordering criterion) {
    return -1;
  }
  if (a is greater than b by the ordering criterion) {
    return 1;
  }
  // a must be equal to b
  return 0;
}