A simple MODX snippet to get images from instagram using the Instagram Basic Display API.
- Follow these instructions to get your Instagram Basic Display access token link
- Add the token as a system setting named
instagram_access_token - Create a directory inside of
public_html/core/calledclasses - Upload the file inside of
scripts/topublic_html/core/classes/asinstagram.class.php - Create a snippet with the following code inside
<?php
if (!$modx->loadClass('Instagram', MODX_CORE_PATH .'classes/', true, true)) {
die('Could not load class');
}
$token = $modx->getOption('instagram_access_token');
$Instagram = new Instagram($modx, $token);
$tpl = $modx->getOption('tpl', $scriptProperties, '');
$max = $modx->getOption('max', $scriptProperties, 8);
return $Instagram->getPhotos($tpl, $max);| Option | Default | Description |
|---|---|---|
| tpl | Template for each Instagram post | |
| max | 8 | Maximum amount of posts to generate |
| Title | Placeholder | Description |
|---|---|---|
| Type | type | Type of media (Image, Video, Carousel) useful for debugging in case Facebook changes the API |
| Source | src | Link to the image source |
| Link | link | The direct link to the Instagram post |
| Caption | caption | Associated post caption |
| Index | idx | 1-based index variable |
<ul data-instagram-feed>
[[Instagram?
&tpl=`instagram-item`
&max=`6`
]]
</ul>[[- Chunk Name: instagram-item ]]
[[+type:isnt=`IMAGE`:then=`PANIC!!!!! [[+link]]`:else=``]]
<li data-index="[[+idx]]">
<a href="[[+link]]">
<img src="[[+src]]" alt="[[+caption]]">
</a>
</li>