PHPackages                             amirsarhang/instagram-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. amirsarhang/instagram-php-sdk

ActiveLibrary[API Development](/categories/api)

amirsarhang/instagram-php-sdk
=============================

It's Instagram Graph SDK for PHP. With this package you can easily make all requests to Instagram Graph API, like Auth and CRUD. Also, we will have more methods regularly.

3.0.0(11mo ago)5210.4k9[1 issues](https://github.com/amirsarhang/instagram-php-sdk/issues)MITPHPPHP &gt;=8.0CI passing

Since Oct 2Pushed 11mo ago4 watchersCompare

[ Source](https://github.com/amirsarhang/instagram-php-sdk)[ Packagist](https://packagist.org/packages/amirsarhang/instagram-php-sdk)[ Docs](https://github.com/amirsarhang/instagram-php-sdk)[ RSS](/packages/amirsarhang-instagram-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (13)Used By (0)

amirsarhang/instagram-php-sdk
=============================

[](#amirsarhanginstagram-php-sdk)

[![Source Code](https://camo.githubusercontent.com/0cf99499be62fe359f989099565039af31ff089eee825b154b9cb2b798ec96f4/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d616d697273617268616e672f696e7374616772616d2d2d7068702d2d73646b2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/amirsarhang/instagram-php-sdk)[![Latest Version](https://camo.githubusercontent.com/6df9747aeb712d3da9e1c1eb32fbc49be355abc5edfc3735f201d957af967ca8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d697273617268616e672f696e7374616772616d2d7068702d73646b2e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/amirsarhang/instagram-php-sdk)[![Software License](https://camo.githubusercontent.com/7ada401d9e43f7f284248184d81c0c58ffc3fa03e58ed09cdb3053488baf2ca4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d697273617268616e672f696e7374616772616d2d7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://github.com/amirsarhang/instagram-php-sdk/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/1fc03ca83c8b5bd27cc6b489d6a7692101bb4866f4392731d8cada1d393aae7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616d697273617268616e672f696e7374616772616d2d7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Total Downloads](https://camo.githubusercontent.com/e9cd5cbaba31a2632108fdd6bfcd67a4753ed27caa174f9aeff4573af9f3e18a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d697273617268616e672f696e7374616772616d2d7068702d73646b2e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/amirsarhang/instagram-php-sdk)

It's Instagram Graph SDK for PHP.

With this package you can easily make all requests to Instagram Graph API, like Auth and CRUD. Also, we will have more methods regularly.

This project adheres to a [Contributor Code of Conduct](https://github.com/amirsarhang/instagram-php-sdk/blob/master/.github/CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Installation
------------

[](#installation)

The preferred method of installation is via [Composer](http://getcomposer.org/). Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require amirsarhang/instagram-php-sdk
```

Or add the following to your composer.json file:

```
"require": {
      "amirsarhang/instagram-php-sdk": "3.0.0"
},
```

Documentation
-------------

[](#documentation)

### Requirements

[](#requirements)

PHP VersionPackage VersionConnection TypeRequired Parameters`>= 7.0``1.x``Facebook Graph Login``FACEBOOK_APP_ID | FACEBOOK_APP_SECRET``>= 8.0``2.x``Facebook Graph Login``FACEBOOK_APP_ID | FACEBOOK_APP_SECRET``>= 8.0``3.x``Instagram Graph Login``INSTAGRAM_APP_ID | INSTAGRAM_APP_SECRET`\****Please remember that you need a verified Facebook APP to use this sdk.***

### Configuration

[](#configuration)

Put these values in your .env file:

```
INSTAGRAM_APP_ID="" // Get it from your Meta developer dashboard
INSTAGRAM_APP_SECRET="" // Get it from your Meta developer dashboard
INSTAGRAM_GRAPH_VERSION="v21.0" // Your Graph version >= v19.0
INSTAGRAM_CALLBACK_URL="https://yoursite.com/instagram/callback" // Instagram callback after login
```

### Auth &amp; Login

[](#auth--login)

```
use Amirsarhang\Instagram;
...
public function login()
{
    // Go to Meta Documentations to see available permissions
    $permissions = [
        'instagram_business_basic',
        'instagram_business_manage_messages',
        'instagram_business_manage_comments',
    ];

    // Generate Instagram Graph Login URL
    $login = (new Instagram())->getLoginUrl($permissions);

    // Redirect To Instagram Login & Select Account Page
    return header("Location: ".$login);
}
```

- ***Please remember that your added permissions need verified by Meta.***

[Here](https://developers.facebook.com/docs/instagram-platform/instagram-api-with-instagram-login) you can find Meta Permissions.

Generate &amp; Save Page Access Token in your Database.

```
use Amirsarhang\Instagram;
...
public function callback()
{
    // Get 'code' query string from Callback URL (ex. /callback?code=AQD5...)
    $code = $_GET['code'];

    // Generate Page Access Token After User Callback To Your Site
    return Instagram::getPageAccessToken($code);
}
```

### Sample Response

[](#sample-response)

```
{
  "access_token": "IGQWRNSElpaDlWa0h1OXjsDhr8V3o0RHg2c2MyS2VTbmlyZA3k4ZAF8yT0Vh...",
  "token_type": "bearer",
  "expires_in": 5180249, // Access token expire timestamp (about 2 months)
  "id": "1234567890123456", // Instagram page ID
  "name": "Test Page", // Instagram page name
  "username": "test_page" // Instagram page username
}

```

After storing selected page data by user in your database, then you need to call `subscribeWebhook()` to register this page for get real time Events.

```
use Amirsarhang\Instagram;
...
public function registerWebhook()
{
    $token = "";
    $instagram_page_id= "";
    $instagram = new Instagram($token);

    // Default subscribe with "messages" field
    return $instagram->subscribeWebhook($instagram_page_id, $token);

    // You can pass your necessary fields as an Array in the last parameter.
    // Your app does not receive notifications for changes to a field
    // unless you configure Page subscriptions in the App Dashboard and subscribe to that field.
    return $instagram->subscribeWebhook($instagram_page_id, $token, ["messages", "comments"]);
}
```

Check this [link](https://developers.facebook.com/docs/graph-api/webhooks/reference/instagram/) for more details about page subscriptions.

### Usage

[](#usage)

```
use Amirsarhang\Instagram;
...
public function userInfo()
{

    $instagram = new Instagram($access_token);

    $endpoint = '/me?fields=id,name';

    return $instagram->get($endpoint);

}
```

Methods
-------

[](#methods)

### *Comment Methods*

[](#comment-methods)

### Get Comment Data

[](#get-comment-data)

```
// Get default Comment fields data (Timestamp, text, id)
$get_comment = $instagram->getComment($comment_id);

// If you need other fields, you can send them as an array
$get_comment = $instagram->getComment($comment_id, ['media','like_count']);

return $get_comment;
```

### Add Comment

[](#add-comment)

```
return $instagram->addComment($recipient_id, 'Test Reply');
```

### Delete Comment

[](#delete-comment)

```
return $instagram->deleteComment($comment_id);
```

### Hide &amp; UnHide Comment

[](#hide--unhide-comment)

```
return $instagram->hideComment($comment_id, true); // false for UnHide
```

### *Messaging Methods*

[](#messaging-methods)

### Get Message Data

[](#get-message-data)

```
// Get default Message fields data (message, from, created_time, attachments, id)
$get_message = $instagram->getMessage($message_id);

// If you need other fields, you can send them as an array
$get_message = $instagram->getMessage($message_id, ['attachments','from']);

return $get_message;
```

### Send Text Message (Direct Message)

[](#send-text-message-direct-message)

```
return $instagram->addTextMessage($recipient_id, 'Test DM');
```

### Send Media Message (Direct Message)

[](#send-media-message-direct-message)

```
return $instagram->addMediaMessage($recipient_id, '');
```

I will add more Useful methods as soon as possible :)

Check out the [documentation website](https://amirsarhang.github.io/instagram-php-sdk/) for detailed information and code examples.

Contributing
------------

[](#contributing)

Contributions are welcome! Please read [CONTRIBUTING](https://github.com/amirsarhang/instagram-php-sdk/blob/master/.github/CONTRIBUTING.md) for details.

Copyright and License
---------------------

[](#copyright-and-license)

The amirsarhang/instagram-php-sdk library is copyright © Amirhossein Sarhangianand licensed for use under the MIT License (MIT). Please see [LICENSE](https://github.com/amirsarhang/instagram-php-sdk/blob/master/LICENSE) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance51

Moderate activity, may be stable

Popularity38

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~122 days

Recently: every ~264 days

Total

12

Last Release

348d ago

Major Versions

v1.x-dev → v2.x-dev2022-10-06

2.0.0 → v3.x-dev2025-06-04

PHP version history (3 changes)1.0.0PHP ^7.2

1.0.1PHP &gt;=7.0

v2.x-devPHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56595198?v=4)[Amirhossein Sarhangian](/maintainers/amirsarhang)[@amirsarhang](https://github.com/amirsarhang)

---

Top Contributors

[![amirsarhang](https://avatars.githubusercontent.com/u/56595198?v=4)](https://github.com/amirsarhang "amirsarhang (11 commits)")

---

Tags

graph-apiinstagraminstagram-apiinstagram-graph-apiinstagram-phpinstagramgraph-apiinstagram-sdkInstagram-PHPInstagram-Library

### Embed Badge

![Health badge](/badges/amirsarhang-instagram-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/amirsarhang-instagram-php-sdk/health.svg)](https://phpackages.com/packages/amirsarhang-instagram-php-sdk)
```

###  Alternatives

[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[facebook/php-ads-sdk

PHP SDK for Facebook Business

9014.1M8](/packages/facebook-php-ads-sdk)[cosenary/instagram

An easy-to-use PHP Class for accessing Instagram's API.

1.5k943.5k9](/packages/cosenary-instagram)[pgrimaud/instagram-user-feed

This is a scraper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.

940657.1k5](/packages/pgrimaud-instagram-user-feed)[jstolpe/instagram-graph-api-php-sdk

Instagram Graph API PHP SDK

13998.4k2](/packages/jstolpe-instagram-graph-api-php-sdk)[wrav/oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.

36205.0k3](/packages/wrav-oembed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
