Recent media from an authorized Instagram user

Get the most recent media published by an authorized user. 

To make pagination work, you must set up a route to use the final segment as a "slug". Here's a screenshot of how this is set up on this site.

Example of setting up a route in Craft CMS

On this code example page, the next page link has been purposely disabled because how how search engines were spidering this site. 

Note: This code example is for Pic Puller for Craft 2. If you're using Craft 3, the only difference is "picpuller" changes to "picPuller". The full Pic Puller for Craft 3 can be found here.


Documentation for this code example: Recent media

The code block below is generating the section that follows it.

{% set nextmaxid = craft.request.getSegment(3) %}

{% for instagramdata in craft.picpuller.media_recent({'user_id' : 1,  'use_stale_cache' : true, 'limit': 4, 'max_id': nextmaxid }) %}

  {% if loop.first %}
    <p>Status: {{ instagramdata.status }}</p>
    <p>Error Type: {{ instagramdata.error_type }}</p>
    <p>Error Message: {{ instagramdata.error_message }}</p>
    <hr>
  {% endif %}

  {% if instagramdata.status == 'true' %}
    <p>Loop Index: {{ loop.index }}</p>
    {% if instagramdata.video_low_resolution != '' %}
      <p>THERE IS VIDEO HERE!</p>
      <p>{{ instagramdata.video_low_resolution }}</p>
    {% endif %}
    <p><img src="{{instagramdata.low_resolution}}" alt='{{instagramdata.caption}}'></p>
    <p>{{ instagramdata.media_id }}</p>
    <p>The Instagram link: {{ instagramdata.link }}</p>
    <p>likes: {{ instagramdata.likes }}</p>
    <p>number of comments: {{ instagramdata.comment_count }}</p>
    <p>caption: {{instagramdata.caption}}</p>
    <p>created_time: {{ instagramdata.created_time }}</p>
  {% else %}
    <p>Error Type: {{ instagramdata.error_type }}</p>
    <p>Error Message: {{ instagramdata.error_message }}</p>
  {% endif %}
  {% if loop.last and instagramdata.next_max_id|default is not empty and craft.request.getSegment(3) is empty %}
    <p><a href="/code/media_recent/{{ instagramdata.next_max_id}}" class='btn btn-default'>NEXT ></a></p>
  {% endif %}

{% endfor %}

Status: 1

Error Type: NoError

Error Message: Nothing wrong here. Move along.


Loop Index: 1

It's available in a way though.

1974469831772470117_1500897

The Instagram link: https://www.instagram.com/p/BtmudnOhftl/

likes: 31

number of comments: 1

caption: It's available in a way though.

created_time: 1549595167

Loop Index: 2

Carol Kane!

1974387637842483109_1500897

The Instagram link: https://www.instagram.com/p/BtmbxiKhhel/

likes: 18

number of comments: 1

caption: Carol Kane!

created_time: 1549585369

Loop Index: 3

That’s “movie” snow.

1970521380651165671_1500897

The Instagram link: https://www.instagram.com/p/BtYssFkBmfn/

likes: 35

number of comments: 0

caption: That’s “movie” snow.

created_time: 1549124475

Loop Index: 4

THERE IS VIDEO HERE!

https://scontent.cdninstagram.com/vp/d2f46adc3451f335e86988b5cc1c4acd/5C6DD549/t50.2886-16/51419372_283471802336113_5658826229711561001_n.mp4?_nc_ht=scontent.cdninstagram.com

Making cheese at Beecher's

1966253068693804848_1500897

The Instagram link: https://www.instagram.com/p/BtJiL-SBBcw/

likes: 20

number of comments: 0

caption: Making cheese at Beecher's

created_time: 1548615679

NEXT >

This "next" button is disabled for this code example page.