Giter VIP home page Giter VIP logo

yizack / instagram-feed Goto Github PK

View Code? Open in Web Editor NEW
94.0 5.0 29.0 59 KB

PHP library to retrieve an Instagram profile feed. Embed a simple Instagram feed of your authorized Instagram accounts on your website with our example using the library and Glide.js. [auto-refreshing acces token support]

Home Page: https://instagram-feed.yizack.com

License: MIT License

PHP 100.00%
instagram php instagram-api instagram-feed instagram-profile facebook

instagram-feed's Introduction

instagram-feed

Packagist

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)

Live Demo

Requeriments

  • PHP Hosting (with composer and fopen() 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:

composer require yizack/instagram-feed

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.

require "vendor/autoload.php";
use Yizack\InstagramFeed;

$feed = new InstagramFeed(
  "long-lived-access-token" // Paste your long-lived-access-token here
);

To retrieve your Instagram feed array use the getFeed() function.

$array = $feed->getFeed();

Or loop it directly in a foreach method wherever you need it.

foreach ($feed->getFeed() as $value) {
    // your code
}

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 fopen().

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.

  1. Go to Meta for Developers site, login and create App. Select the app type as None.
    Meta App Step 1
  2. Provide your App details.
    Meta App Step 2
  3. Look for Instagram Basic Display product, and click on Set up to use the Instagram API.
    Meta App Step 3
  4. Scroll down until you see an alert and click on Settings to update your App settings.
    Meta App Step 4
  5. Scroll down and click on the Add Platform button.
    Meta App Step 5
  6. Select the platform Website.
    Meta App Step 6
  7. Enter your Site URL and save changes.
    Meta App Step 6

Instagram Basic Display API

Now it is time to authorize your instagram account.

  1. Back to Products > Instagram > Basic Display. Create new App.
    Instagram App Step 1
  2. Fill OAuth Redirect, Deauthorize Callback and Data Deletion Request URL with your site URL and save changes.
    Instagram App Step 2
  3. Add Instagram testers.
    Instagram App Step 3
  4. Enter your Instagram username and select your profile.
    Instagram App Step 4
  5. Go to your Instagram account settings page > App and Websites > Tester invites, accept the invite.
    Instagram App Step 5
  6. 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.
    Instagram App Step 6
  7. Login and authorize the App.
    Instagram App Step 7
  8. Click on I Understand checkbox and copy the generated token.
    Instagram App Step 8
  9. Paste your token in your code.

Repository

Yizack/instagram-feed on GitHub.

instagram-feed's People

Contributors

vachzar avatar yizack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

instagram-feed's Issues

Getting the below error in line 59

post() in C:\xampp\htdocs\insta\index.php:59 Stack trace: #0 {main} thrown in C:\xampp\htdocs\insta\index.php on line 59

the line 59 is:

php notice

This might not look important since it is a php notice, however, it seems the json will not be updated because of this notice.

( ! ) Notice: Trying to access array offset on value of type null in C:\wamp64\www\testing\instagram-feed-master\functions.php on line 24

which is:
$date_json = request("$site/update.json")["update"];

the value returned is null from request() function. Also, the return response was passed through json_decode(). Update is to be accessed using $response->update.

I suggest to avoid this call and replace with with file get content function:

$update_file = direname(FILE) ."/update.json";
$date_json = file_get_contents( $update_file );
:
:
if(strtotime($date) - strtotime($date_json) > 86400)
{
fwrite($update_file , json_encode($array, JSON_PRETTY_PRINT));
:
}
๐Ÿ‘

white screen

help me plz , i try setting up but result white screen ....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.