ideato / instagram-feed
Retrieve data from Instagram feed
0.0.1
2017-10-13 21:05 UTC
Requires
- guzzlehttp/guzzle: ^6.3
- symfony/cache: ^3.3
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2024-11-10 00:35:14 UTC
README
Retrieve data from Instagram feed
Requirements
- PHP 7.1
Installation
composer require ideato/instagram-feed
Usage
InstagramFeed requires a Guzzle HTTP Client and an Instagram access token.
Here you can find a tool for generate your own instagram access token
$instagramFeed = new InstagramFeed\InstagramFeed( new \GuzzleHttp\Client(), 'your own access token' ); $media = $instagramFeed->getMedia(); //will returns array of InstagramFeed\Model\Media objects
Caching
Instagram APIs come out with low rate limit. This means you have to cache responses in order to prevent errors. The library provides a PSR-6 cache decorator with allows you to easily cache responses.
$instagramFeed = new InstagramFeed\InstagramFeed( new \GuzzleHttp\Client(), 'your own access token' ); $instagramCachedFeed = new InstagramFeed\InstagramCachedFeed( new \Symfony\Component\Cache\Adapter\FilesystemAdapter(), $instagramFeed, $ttl //defaults to 600 seconds ); $media = $instagramCachedFeed->getMedia(); //will returns array of InstagramFeed\Model\Media objects
Symfony Integration
Instagram Feed can be easily configured as a service on your Symfony application.
services.yml parameters: app_instagram_access_token: 'your own token' services: #if you already defined Guzzle as service, just use yours app.guzzle_client: class: GuzzleHttp\Client app.instagram_feed: class: InstagramFeed\InstagramFeed arguments: - "@app.guzzle_client" - "%app_instagram_access_token%" app.instagram_cached_feed: class: InstagramFeed\InstagramCachedFeed arguments: - "@cache.app" - "@app.instagram_feed" public: true
Then you can retrieve posts with:
$this->get('app.instagram_cached_feed')->getMedia();
TODO
- add support to other api endpoints
- add support to other Instagram types (eg. video, gallery)