PHP code example of bubalubs / craft-instagram-api
1. Go to this page and download the library: Download bubalubs/craft-instagram-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bubalubs / craft-instagram-api example snippets
{% set instagramMedia = craft.instagram.getMedia() %}
{% if instagramMedia|length %}
<div class="grid grid-cols-4 gap-4">
{% for media in instagramMedia %}
<div>
<a href="{{ media.permalink }}" title="View on Instagram" target="_blank">
<img src="{{ media.media_url }}" alt="{{ media.caption ?? 'Instagram image' }}"/>
</a>
</div>
{% endfor %}
</div>
{% endif %}
use bubalubs\instagramapi\InstagramAPI;
// ...
$instagramMedia = InstagramAPI::getInstance()->instagram->getMedia();
foreach ($instagramMedia as $media) {
$mediaUrl = $media['media_url'];
$file = file_get_contents($mediaUrl);
// Strip query string from filename
$newFilename = pathinfo(explode('?', $mediaUrl)[0], PATHINFO_BASENAME);
// Check if directory exists
if (!file_exists(Craft::$app->path->getStoragePath() . '/instagram')) {
mkdir(Craft::$app->path->getStoragePath() . '/instagram', 0775, true);
}
// Save file locally
file_put_contents(Craft::$app->path->getStoragePath() . '/instagram/' . $newFilename, $file);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.