Download the PHP package yizack/instagram-feed without Composer
On this page you can find all versions of the php package yizack/instagram-feed. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yizack/instagram-feed
More information about yizack/instagram-feed
Files in yizack/instagram-feed
Package instagram-feed
Short Description PHP library to retrieve an Instagram profile feed, embed the feed of your authorized Instagram accounts on your website. The library uses the Instagram Basic Display API with auto-refreshing access token support
License MIT
Informations about the package instagram-feed
instagram-feed
PHP library to retrieve an Instagram profile feed, embed the feed of your authorized Instagram accounts on your website. The library uses the Instagram Basic Display API with auto-refreshing access token support.
(Live Demo)
Requeriments
- PHP Hosting (with
composer
,file_get_contents()
,file_put_contents()
support) - Meta Developer App [Guide]
- Instagram Basic Display API [Guide]
Installation
To install the library, make sure you have Composer installed and using your command terminal run the following:
Use
Installing this library will allow you to use the InstagramFeed
class by simply importing the composer autoload.
Import the composer autoload, use the namespace Yizack\InstagramFeed
and initialize the InstagramFeed
object.
To retrieve your Instagram feed array use the getFeed()
function.
Or loop it directly in a foreach
method wherever you need it.
The getFeed()
function also accepts a comma-separated list of fields to be returned.
For a list of all available fields see: https://developers.facebook.com/docs/instagram-basic-display-api/reference/media#fields
About the code
InstagramFeed
constructor arguments
Argument | Type | Description | Optional | Default value |
---|---|---|---|---|
token |
string | Your Instagram Basic Display long-lived-access-token . |
No | |
path |
string | The path where the updated file will be saved on your server. | Yes | ig_token |
filename |
string | The name of the file in which the date of the last token update will be stored. | Yes | updated.json |
getFeed()
function
Updates the date of the last token update and requests feed data from an Instagram account.
Returns an array with the data of the last 25 posts with the following data for each one:
Key | Description |
---|---|
username |
Instagram username. |
permalink |
Instagram post permalink. |
timestamp |
Instagram post timestamp. |
caption |
Instagram post caption. |
id |
Instagram post identifier. |
Long-Lived Access token
This approach uses Long-Lived Access Tokens obtained by authorizing your Instagram account with your Meta App.
Since Long-lived tokens are valid for 60 days and can be refreshed as long as they are at least 24 hours old and not expired, the getFeed()
method will refresh your token everytime it is been called if 24 hours have passed.
Tokens that have not been refreshed in 60 days will expire and can no longer be refreshed, so be sure to visit often the site where you placed the feed.
Example of use
Check the example
folder for details.
Requeriments Guide
PHP Hosting
You can use any PHP Hosting unless it does not support file_get_contents()
and file_put_contents()
.
Meta Developer App
In order to use the Instagram API, we must first create a Meta App. Follow the steps below to create a Meta App.
- Go to Meta for Developers site, login and create App. Select the app type as None.\
- Provide your App details.\
- Look for Instagram Basic Display product, and click on Set up to use the Instagram API.\
- Scroll down until you see an alert and click on Settings to update your App settings.\
- Scroll down and click on the Add Platform button.\
- Select the platform Website.\
- Enter your Site URL and save changes.\
Instagram Basic Display API
Now it is time to authorize your instagram account.
- Back to Products > Instagram > Basic Display. Create new App.\
- Fill OAuth Redirect, Deauthorize Callback and Data Deletion Request URL with your site URL and save changes.\
- Add Instagram testers.\
- Enter your Instagram username and select your profile.\
- Go to your Instagram account settings page > App and Websites > Tester invites, accept the invite.\
- Back to Products > Instagram > Basic Display > User Token Generator, you Instagram account should appear in the list, then click Generate Token button for authorize and generate long-lived access token for Instagram.\
- Login and authorize the App.\
- Click on I Understand checkbox and copy the generated token.\
- Paste your token in your code.
Repository
Yizack/instagram-feed on GitHub.