About Instagram Feed

Represents the instagram feed of a user.

Category Social, Feeds, Services
Modules that provide or work with social networking services and/or external feeds.
Release StateStable
Should be safe for use in production environments. *
Authorjustb3a
Module Version1.0.1
Class NameInstagramFeed
Compatibility3.0
Date AddedOctober 1, 2015
Last UpdatedOctober 6, 2016
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/InstagramFeed/
How to install or uninstall modules

README

Instagram Feed

Represents the instagram feed of any user or recently tagged media.

Instructions

Register your app on Instagram

First you have to register your application on Instagram.

Enter a name, description and (really important) the correct redirect url. You can add more than one. If you want to generate the code and access token to authenticate against instagram from the ProcessWire module setting page, you have to add a url similar as: http://page.dev/processwire/module/edit?name=InstagramFeed/. Just install the module and copy the url inside the address bar.

Register your app on Instagram

When you've done you'll receive a Client ID and a Client Secret.

Receive Client ID and Secret

Install module

Next you have to install the module and enter at least Client ID and Client Secret in module settings.

Click submit.

Generate access token

There are a few steps involved in the authentication process:

  • You get directed to the Instagram website to allow access to your application
  • You get a code back from Instagram
  • This code is used to send a request to Instagram to get an access_token

If you entered the correct redirect url (instagram) and saved Client ID as well as Client Secret (ProcessWire module settings), you only have to click the link get Access Token in module settings.

If everything went well you'll see an access token in module settings.

The access token does not specify an expiration time. Either the user revokes access, or Instagram expires the token after some period of time.Just click the link again to create a new access token.

Generate Access Token

Note: Since 1. of June 2016 every new app created starts in Sandbox mode (Apps are restricted to 10 users, data is restricted to the 10 users and the 20 most recent media from each of those users). read more

More settings..

You can specify some more settings:

  • Username: Instagram username to display content from (default: self)
  • Image Count: Count of media to return

... and use it!

For example:

<?php $feed = $modules->get('InstagramFeed')->getRecentMedia(); ?>

<div class="instagram">
  <?php foreach ($feed as $media): ?>
    <?php if ($media['type'] === 'image'): ?>
      <a href="<?=$media['link']; ?>" class="instagram-item">
        <picture>
          <source media="(min-width: 55rem)" srcset="<?=$media['images']['standard_resolution']['url']; ?>">
          <source media="(min-width: 45rem)" srcset="<?=$media['images']['low_resolution']['url']; ?>">
          <source srcset="<?=$media['images']['thumbnail']['url']; ?>">
          <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
        </picture>
      </a>
    <?php else: ?>
      // output video
    <?php endif; ?>
  <?php endforeach; ?>
</div>

Example

You can output any value explained here.

If you want to output another feed, you can pass a username:

  • $modules->get('InstagramFeed')->getRecentMedia('username');

Priority:

  1. argument passed by
  2. username entered in module settings
  3. default 'self', to get the most recent media published by the owner of the access token

Available endpoints

Get the instagram feed of any user

  • getRecentMedia($username = 'self')
<?php $feed = $modules->get('InstagramFeed')->getRecentMedia(); ?>

Get a list of recently tagged media

  • getRecentMediaByTag($tagname)
<?php $feed = $modules->get('InstagramFeed')->getRecentMediaByTag('processwire'); ?>

Get a list of recent comments on a media object.

  • getRecentComments($media)
<?php $comments = $modules->get('InstagramFeed')->getRecentComments($media); ?>

For example:

<?php 
$feed = $modules->get('InstagramFeed')->getRecentMedia(); ?>

<div class="instagram>
  <?php foreach ($feed as $media): ?>
    <?php if ($media['type'] === 'image'): ?>
      <a href="<?=$media['link']; ?>" class="instagram-item">
        <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
      </a>
      // display comments
      $comments = $modules->get('InstagramFeed')->getRecentComments($media); ?>
      <?php if ($comments): ?>
        <ul>
          <?php foreach ($comments as $comment): ?>
            <li><?=$comment['text']></li>
          <?php endforeach; ?>
        </ul>
      <?php endif; ?>
    <?php endif; ?>
  <?php endforeach; ?>
</div>

Links:

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.