getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

[instagram-feed] instagram.getInstagramMedia limit does not work #328

Closed FabriceJoseph closed 1 year ago

FabriceJoseph commented 1 year ago

Hi, For the past few months, the limit of 12 posts that I pass as a parameter of the instagram.getInstagramMedia function no longer has any effect. The amount of instagram posts collected continues to increase. Today, it's 27 posts recovered (instead 12). I have version 1.1.0 of the plugin and the code is as follows:

{% for image in instagram.getInstagramMedia(12, false).all %}
     <a style="font-size: 0;" href="{{ image.meta.permalink }}" target="_blank">
         <img src="{{ image.cropZoom(200, 200).url }}" />
     </a>
{% endfor %}

Anyone else have the same problem?

Thank you for your help Fabrice

xadammr commented 1 year ago

I am experiencing this as well. As a workaround:

{% set i = 1 %}
{% for image in instagram.getInstagramMedia(4, false).all if i < 12 %}
<article>
    <a href="{{ image.meta.permalink }}" target="_blank" title="{{ image.meta.caption }}">
        <img src="{{ image.cropZoom(600, 600).url }}" />
    </a>
</article>
{% set i = I + 1 %}
{% endfor %}
FabriceJoseph commented 1 year ago

Hi @xadammr. Thank you for your answer. I did pretty much the same thing :

  {% for image in instagram.getInstagramMedia(12, false).all %}
    {% if(loop.index <= 12) %}
    <a style="font-size: 0;" href="{{ image.meta.permalink }}" target="_blank">
      <img src="{{ image.cropZoom(200, 200).url }}" />
    </a>
    {% endif %}
  {% endfor %}
rhukster commented 1 year ago

In typical Facebook/Instagram/Meta fashion it appears they've changed the API with no backwards compatibility. It seems there's no longer a limit field for the /media endpoint: https://developers.facebook.com/docs/instagram-basic-display-api/reference/media

You guys are on the right track, I would modify this template to do this:

{% for image in instagram.getInstagramMedia|slice(0,12) %}

That should work fine using Twig's slice function to start at 0 offset, and get 12 entries

rhukster commented 1 year ago

Released with this fix in the display-media.html.twig template + updated the docs

FabriceJoseph commented 1 year ago

Thank you @rhukster . Netherless, to retrieve the very last 12 posts, I had to use this syntax with the .all :

{% for image in instagram.getInstagramMedia(0,false).all|slice(0,12) %}