Plugin for Craft CMS that makes it easy to interact with the Instagram Basic Display API and Instagram oEmbed.

Overview

Instagram Basic Display plugin for Craft CMS 3.x

This plugin creates endpoints in your Craft install for you to consume the Instagram Basic Display API as well as the oEmbed API. It also provides some helper methods for dealing with your access token and getting refresh tokens.

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require melvilleco/instagram-basic-display
    
  3. Obtain a long-lived access token from Instagram (see example video below) and insert it into your database.

How to get an initial access token for the Instagram Basic Display API - Watch Video

Instagram Basic Display Overview

This plugin provides some helper methods and endpoints for working with the Instagram Basic Display API and the Instagram OEmbed service.

The plugin makes available several useful console commands and controller actions to help you access your Instagram content.

Configuration

Configuration is done via the src/config.php config file. It should be renamed to instagram-basic-display.php and copied to your config/ directory to take effect.

The most likely options you may want to change are cache_duration and fields. fields simply determines what data is returned by the request.

Inserting Your Access Token

By default, Instagram User Access Tokens are short-lived and are valid for one hour. However, short-lived tokens can be exchanged for long-lived tokens.

Long-lived tokens are valid for 60 days and can be refreshed as long as they are at least 24 hours old but have not expired, and the app user has granted your app the instagram_graph_user_profile permission.

After you obtain your long-lived token, run the following command to insert it into your database:

  ./craft instagram-basic-display/token/insert [YOUR_TOKEN_HERE]

Refreshing Your Token

As long-lived tokens are only valid for 60 days, you will need to periodically request a refreshed token. You can easily do this by setting up a cron task that calls the refresh method of the plugin:

  ./craft instagram-basic-display/token/refresh

Your old token will be used to obtain a new one, and the new token will be inserted into the database.

Commands and Endpoints

Console Commands

The following console commands are available:


Get the expiration date/time of the current token:

  ./craft instagram-basic-display/token/exp

Echo out the current access token:

  ./craft instagram-basic-display/token/get

Manually insert an access token into the database:

  ./craft instagram-basic-display/token/insert

Refresh the current token:

  ./craft instagram-basic-display/token/refresh

Accessing your Instagram feed as JSON

If accessing your feed from inside a Vue or React component, you can hit the following endpoint to get a JSON response:

  /actions/instagram-basic-display/feed/get

Getting Your Feed in Twig

You can also output your feed inside your Twig templates using a {% for %} loop:

<ul>
   {% for media in craft.instagram.getFeed() %}
      {% if media.media_type == 'IMAGE' %}
         <li>
            <a href="{{ media.permalink }}">
               <img src="{{ media.media_url }}" alt="">
            </a>
         </li>
      {% endif %}
   {% endfor %}
</ul>

Instagram Basic Display Roadmap

Some things to do, and ideas for potential features:

  • Add OEmbed docs.
  • Create better docs for how to get an initial token.
  • Work out solution for scaling images.

Brought to you by Jonathan Melville

You might also like...
A platform for CMS version detection, exploit suggestion and CVE display based on vulnerability

A platform for CMS version detection, exploit suggestion and CVE display based on vulnerability

Provides a twig editor field with Twig & Craft API autocomplete
Provides a twig editor field with Twig & Craft API autocomplete

Twigfield for Craft CMS 3.x & 4.x Provides a twig editor field with Twig & Craft API autocomplete Requirements Twigfield requires Craft CMS 3.0 or 4.0

Basic Bedrock Theme for Concrete CMS

Basic Bedrock Theme Package for Concrete CMS v9 Basic Bedrock Theme Package for Concrete CMS v9 Concrete CMS Bedrock Documentation Description Persona

PHPVibe Open source video CMS / Video Sharing CMS / Youtube Api v3 / Video Embeds
PHPVibe Open source video CMS / Video Sharing CMS / Youtube Api v3 / Video Embeds

PHPVibe Video CMS Free Video Sharing CMS The modern choice of design inspired by Youtube and a social videos sharing module that may just cut it for y

Baicloud CMS is a lightweight content management system (CMS) based on PHP and MySQL and running on Linux, windows and other platforms

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

GetSimple CMS - a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP

GetSimple CMS is a flatfile CMS that works fast and efficient and has the best UI around, it is written in PHP.

Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS
Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS

Flextype is an open-source Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS. Building this Content Management System, we focused on simplicity. To achieve this, we implemented a simple but powerful API's.

BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the project website for more information.

BaiCloud-cms About BaiCloud-cms is a powerful open source CMS that allows you to create professional websites and scalable web applications. Visit the

Comments
  • Suggestion - Multi-site support

    Suggestion - Multi-site support

    It would be awesome if the plugin would support a multi-site configuration and allow for different access tokens per site, if required.

    Is this something you would consider adding at this stage? Maybe all of the commands could just allow for an optional "site.handle" - ./craft instagram-basic-display/token/refresh

    Cheers.

    enhancement 
    opened by cloudgrayau 1
Owner
Jonathan Melville
Jonathan Melville
Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support

Plugin Vite Related Articles: Vite.js Next Generation Frontend Tooling + Craft CMS A Vite Buildchain for Craft CMS Plugins Requirements Craft CMS 3.0.

nystudio107 8 Dec 30, 2022
Provides Twig template IDE autocomplete of Craft CMS & plugin variables

Autocomplete for Craft CMS 3.x Provides Twig template IDE autocompletion for Craft CMS and plugin/module variables and element types. Works with PhpSt

nystudio107 35 Dec 21, 2022
A plugin for Craft CMS 3.X that allows for GraphQL search functionality for matching on fields of nested entries.

Nested Entry GraphQL Plugin This Craft CMS plugin allows for performing graphQL search queries that match on fields on nested entries-as-a-field. What

Rubin EPO 2 Sep 10, 2021
Element Relations Plugin for Craft CMS 3.x

Element Relations Plugin for Craft CMS 3.x This plugin shows all relations of an element. For example, where an asset, entry or any other element is l

Frederic Köberl 2 Jul 18, 2022
Monet Plugin for Craft CMS

A Monet field can be added to asset elements which will generate and store an efficient placeholder image to be displayed inline, whilst the full asset is loading.

Chris Dyer 1 Jan 21, 2022
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.

About Craft CMS Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond. It features: An intuitive, user-

Craft CMS 2.9k Jan 1, 2023
Provides autocompletion for Craft CMS and plugins in Twig templates.

Autocomplete for Craft CMS Provides autocompletion for Craft CMS and plugins in Twig templates. Currently works with PhpStorm only, as VSCode does not

PutYourLightsOn 12 Nov 23, 2021
Allows the use of the Vite.js next generation frontend tooling with Craft CMS

Vite plugin for Craft CMS 3.x Allows the use of the Vite.js next generation frontend tooling with Craft CMS Related Article: Vite.js Next Generation F

nystudio107 38 Dec 30, 2022
A BlurHash implementation for Craft CMS.

BlurHash plugin for Craft CMS 3.x Render a BlurHash from a given asset in Craft CMS. A BlurHash is a compact representation of a placeholder for an im

Dodeca Studio 8 Nov 12, 2022
Edit richt text content in Craft CMS using Article by Imperavi.

Article Editor About the plugin This plugin brings the powerful Article Editor from Imperavi to Craft CMS, allowing you to make create beautiful rich

Creativeorange 6 Mar 30, 2022