beloop/instagram-bundle
Read-only Symfony bundle from the Beloop LMS component suite. Licensed under MIT. Development, issues, questions, and pull requests are handled in the main beloop/components repository, not in this package.
Installation Add the bundle via Composer (though note the package is archived and unmaintained):
composer require beloop/instagram-bundle
Register the bundle in config/bundles.php:
Beloop\InstagramBundle\BeloopInstagramBundle::class => ['all' => true],
Configuration
Configure the bundle in config/packages/beloop_instagram.yaml:
beloop_instagram:
client_id: '%env(INSTAGRAM_CLIENT_ID)%'
client_secret: '%env(INSTAGRAM_CLIENT_SECRET)%'
redirect_uri: '%env(INSTAGRAM_REDIRECT_URI)%'
First Use Case: OAuth Flow Trigger the OAuth flow in a controller:
use Beloop\InstagramBundle\Controller\InstagramController;
class MyController extends AbstractController
{
public function instagramLogin(InstagramController $controller)
{
return $controller->login();
}
}
Route it in config/routes.yaml:
instagram_login:
path: /login/instagram
controller: App\Controller\MyController::instagramLogin
OAuth Flow
login()./login/instagram/check (default route).InstagramService to fetch user data:
$userData = $this->get('beloop_instagram.service')->getUserData($accessToken);
Media Integration Fetch user media (photos/videos) with pagination:
$media = $this->get('beloop_instagram.service')->getUserMedia($accessToken, [
'count' => 10,
'offset' => 0,
]);
Event-Driven Extensions
Subscribe to bundle events (e.g., instagram.login.success) to extend logic:
// src/EventListener/InstagramLoginListener.php
public function onInstagramLoginSuccess(InstagramLoginEvent $event)
{
$user = $event->getUser();
// Custom logic (e.g., sync with your DB)
}
Register the listener in services.yaml:
services:
App\EventListener\InstagramLoginListener:
tags:
- { name: 'kernel.event_listener', event: 'instagram.login.success' }
Deprecated API
spatie/instagram.No Active Maintenance
Token Expiry
$service->refreshAccessToken($refreshToken);
Enable Debug Mode
Add to config/packages/beloop_instagram.yaml:
debug: true
Logs HTTP requests/responses to var/log/dev.log.
Common Errors
Invalid OAuth state: Ensure redirect_uri matches Instagram’s registered URI.Missing permissions: Request user_media scope explicitly in the OAuth flow.Custom Services
Extend Beloop\InstagramBundle\Service\InstagramService to add methods (e.g., getUserStories()).
Twig Integration Pass user/media data to templates:
{% for media in instagram_media %}
<img src="{{ media.images.standard_resolution.url }}">
{% endfor %}
Database Sync Use Doctrine listeners to sync Instagram data:
// src/EventListener/InstagramMediaSyncListener.php
public function postLoad(User $user, InstagramMediaEvent $event)
{
$user->addInstagramMedia($event->getMedia());
$this->entityManager->flush();
}
How can I help you explore Laravel packages today?