Save any resources from Instagram
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

License Total Downloads Build Status Latest Stable Version

InstaSave 🤘 📷 💻

You can fetch all resources from instagram and download them with your program. At least PHP 7.0 is required.

InstaSave support public feeds, it also support playlist, IGTV and HQ users profile pictures as well.



InstaSave uses Composer to make things easy. Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.

#Basic Setup

Learn to use composer and run this command line:

composer require alshf/instasave

#How to use

Make sure you have composer's autoload file included

require 'vendor/autoload.php';


use InstaSave\URL\URL;
use Instasave\InstaSave;

try {
    // First we create URL object, This object do Validation check on URL.
    // You can also access URL with $absoluteUrl property.
    $url = new URL('');

    // Create an InstaSave object, InstaSave use injected URL and pass it to the Client and send GET request
    // to the instagram website and fetch a JSON as a response, then it will pass it to the EntityCollector to 
    // detect instagram feed type and suitable response to parse.
    $instaSave = new InstaSave($url);

    // Parse response to the suitable Entity in InstaSave\Response\Entity.
    $response = $instaSave->fetch();
} catch (Exception $e) {
    echo $e->getMessage();


After you get the Response by calling fetch() method on InstaSave object, it will bring you the Response Entity which it is instance of Entity (Playlist, Feed, Igtv, User) in Instasave\Response\Entity folder.

These response has a type property that you can compare it with InstaSave\Enumeration\Entity.

use InstaSave\Enumeration\Entity;

// Check Response type
$response->type === Entity::Feed;
$response->type === Entity::Playlist;
$response->type === Entity::User;
$response->type === Entity::Igtv;

Responses has lots of properties base on their entity for example feed entity has these properties:


// Dimenstion of the Entity which contains with & height

// Owner of the Entity

// Array of Resources -> Image or Video

You can also check response tree in InstaSave\Response\Sample\Parsed folder.

#Owner Property

This node contains information about the owner of entity.

#Dimension Property

Contains entity dimensions, note that resources property also has dimensions property.

#Resources Property

Contains array of ressources (Image, Video) which blongs to the entity. This property also has a type property that you can compare it with InstaSave\Enumeration\Resource.

use InstaSave\Enumeration\Resource;

// Check Resource type
$response->resources[0]->type === Resource::Video;
$response->resources[1]->type === Resource::Image;

Other resources Property:


// If resource type is Video then it will have these additional property

NOTE: duration Property will be 0 on Playlist Entity.


You can get URL validation Errors with URLValidationException but if you want to get request errors like connection error, Server errors like 5xx or 4xx errors you can catch them with ClientException, you can also catch Response errors with ResponseException.

  • URLValidationException: When URL string pass into InstaSave\URL\URL class if it doesn't validate it will throw exception.
  • ResponseException: When we dont have any response or error on parsing response this exception will throw.
  • ClientException: Connection Errors, 4xx, 5xx will handle with this exception this exception has previous exception which it comes from Alshf\Exceptions\FootmanRequestException.
use InstaSave\URL\URL;
use Instasave\InstaSave;
use Instasave\Exceptions\ClientException;

try {
    // Create invalid URL object
    $url = new URL('');

    // Create InstaSave object from URL
    $instaSave = new InstaSave($url);

    // Try to get Response
} catch (ClientException $e) {
    echo $e->getPrevious()->getStatusCode(); // 404
    echo $e->getPrevious()->getReasonPhrase() // Not Found

For more information check UnitTest file.


Bugs and feature request are tracked on GitHub.


The code on which this package is principally developed and maintained by Ali Shafiee.


InstaSave package is released under MIT.