Skip to content

sakibian/instagram-feed-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Instagram Feed PHP

A lightweight PHP library to fetch and display Instagram media feeds using the Instagram Graph API.

Features

  • 📸 Fetch Instagram posts and media
  • 🖌️ Display images with captions
  • ⚡ Pure PHP implementation (no framework required)
  • 🔒 Secure Instagram Graph API integration
  • 📦 Easy to integrate into existing projects
  • 🛠️ Handles edge cases (missing captions, null values)

Demo

See the live demo: https://instagram-feed-php.herokuapp.com/

Requirements

  • PHP >= 7.2
  • cURL extension enabled
  • Instagram Graph API Access Token

Installation

# Clone the repository
git clone https://github.com/sakibian/instagram-feed-php.git
cd instagram-feed-php

Configuration

  1. Get your Instagram Graph API access token from Facebook Developers

  2. Update the $token variable in the PHP file:

$token = 'YOUR_INSTAGRAM_ACCESS_TOKEN';

Usage

<?php
include 'instagram-feed.php';

// Fetch and display Instagram feed
$feed = getInstagramFeed($token);

foreach ($feed as $post) {
    echo '<img src="' . $post['media_url'] . '" alt="' . $post['caption'] . '">';
}
?>

Handling Null Captions

This implementation includes a fix for the "undefined index caption" error that occurs when Instagram posts have no captions. The solution is inspired by the Dymantic Laravel Instagram Feed MediaParser implementation.

// Caption handling
$caption = isset($post['caption']) ? $post['caption'] : '';

Credits

This project is based on php-curl-instagram-graph by @ribeiroeder, with enhancements for handling null captions and improved error handling.

API Reference

Getting Instagram Posts

The library uses Instagram Graph API to fetch user media:

GET https://graph.instagram.com/me/media

Supported Fields

  • id - Media ID
  • media_type - Type of media (IMAGE, VIDEO, CAROUSEL_ALBUM)
  • media_url - URL of the media file
  • caption - Post caption text
  • timestamp - Publication date

Troubleshooting

Token Expiration

Instagram access tokens expire after 60 days. You'll need to generate a new token when it expires.

Missing Caption Error

If you encounter "undefined index caption" errors, ensure you're using the latest version of this library which includes the null caption handling fix.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Instagram Basic Display API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages