PHPackages                             sofwar/instagram - 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. sofwar/instagram

ActiveLibrary[API Development](/categories/api)

sofwar/instagram
================

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

1.0.0(9y ago)060↓100%BSDPHPPHP &gt;=5.4.0

Since Sep 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/sofwar/Instagram-PHP-API)[ Packagist](https://packagist.org/packages/sofwar/instagram)[ Docs](https://github.com/sofwar/Instagram-PHP-API)[ RSS](/packages/sofwar-instagram/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Instagram PHP API V1
====================

[](#instagram-php-api-v1)

A PHP wrapper for the Instagram API. Feedback or bug reports are appreciated.

> [Composer](#installation) package available.

Requirements
------------

[](#requirements)

- PHP 5.4 or higher
- cURL
- Registered Instagram App

Get started
-----------

[](#get-started)

To use the Instagram API you have to register yourself as a developer at the [Instagram Developer Platform](http://instagr.am/developer/register/) and create an application. Take a look at the [uri guidelines](#samples-for-redirect-urls) before registering a redirect URI. You will receive your `client_id` and `client_secret`.

---

Please note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.

---

### Installation

[](#installation)

I strongly advice using [Composer](https://getcomposer.org) to keep updates as smooth as possible.

```
$ composer require sofwar/instagram

```

### Initialize the class

[](#initialize-the-class)

```
use SofWar\Instagram\Instagram;

$instagram = new Instagram(array(
	'apiKey'      => 'YOUR_APP_KEY',
	'apiSecret'   => 'YOUR_APP_SECRET',
	'apiCallback' => 'YOUR_APP_CALLBACK'
));

echo "Login with Instagram";
```

### Authenticate user (OAuth2)

[](#authenticate-user-oauth2)

```
// grab OAuth callback code
$code = $_GET['code'];
$data = $instagram->getOAuthToken($code);

echo 'Your username is: ' . $data->user->username;
```

### Get user likes

[](#get-user-likes)

```
// set user access token
$instagram->setAccessToken($data);

// get all user likes
$likes = $instagram->getUserLikes();

// take a look at the API response
echo '';
print_r($likes);
echo '';
```

**All methods return the API data `json_decode()` - so you can directly access the data.**

Available methods
-----------------

[](#available-methods)

### Setup Instagram

[](#setup-instagram)

`new Instagram(/);`

`array` if you want to authenticate a user and access its data:

```
new Instagram(array(
	'apiKey'      => 'YOUR_APP_KEY',
	'apiSecret'   => 'YOUR_APP_SECRET',
	'apiCallback' => 'YOUR_APP_CALLBACK'
));
```

`string` if you *only* want to access public data:

```
new Instagram('YOUR_APP_KEY');
```

### Get login URL

[](#get-login-url)

`getLoginUrl()`

```
getLoginUrl(array(
	'basic',
	'likes'
));
```

### Get OAuth token

[](#get-oauth-token)

`getOAuthToken($code, )`

`true` : Returns only the OAuth token `false` *\[default\]* : Returns OAuth token and profile data of the authenticated user

### Set / Get access token

[](#set--get-access-token)

- Set the access token, for further method calls: `setAccessToken($token)`
- Get the access token, if you want to store it for later usage: `getAccessToken()`

### User methods

[](#user-methods)

- `getUser()`
- `searchUser($name, )`
- `getUserMedia($id, )`
- `getUserLikes(, )`
- `getUserMedia(, )`
    - if an `$id` isn't defined or equals `'self'`, it returns the media of the logged in user

> [Sample responses of the User Endpoints.](http://instagram.com/developer/endpoints/users/)

### Relationship methods

[](#relationship-methods)

- `getUserFollows()`
- `getUserFollower()`
- `getUserRelationship($id)`
- `modifyRelationship($action, $user)`
    - `$action` : Action command (follow / unfollow / approve / ignore)
    - `$user` : Target user id

```
// Follow the user with the ID 1521204717
$instagram->modifyRelationship('follow', 1521204717);
```

---

Please note that the `modifyRelationship()` method requires the `relationships` [scope](#get-login-url).

---

> [Sample responses of the Relationship Endpoints.](http://instagram.com/developer/endpoints/relationships/)

### Media methods

[](#media-methods)

- `getMedia($id)`
- `getMediaShort($code)`
- `searchMedia($lat, $lng, )`

> [Sample responses of the Media Endpoints.](http://instagram.com/developer/endpoints/media/)

### Comment methods

[](#comment-methods)

- `getMediaComments($id)`
- `addMediaComment($id, $text)`
- `deleteMediaComment($id, $commentID)`

---

Please note that the authenticated methods require the `comments` [scope](#get-login-url).

---

> [Sample responses of the Comment Endpoints.](http://instagram.com/developer/endpoints/comments/)

### Tag methods

[](#tag-methods)

- `getTag($name)`
- `getTagMedia($name, , , )`
- `searchTags($name)`

> [Sample responses of the Tag Endpoints.](http://instagram.com/developer/endpoints/tags/)

### Likes methods

[](#likes-methods)

**Authenticated methods**

- `getMediaLikes($id)`
- `likeMedia($id)`
- `deleteLikedMedia($id)`

> [Sample responses of the Likes Endpoints.](http://instagram.com/developer/endpoints/likes/)

All `` parameters are optional. If the limit is undefined, all available results will be returned.

---

Signed Header
-------------

[](#signed-header)

In order to prevent that your access tokens gets stolen, Instagram recommends to sign your requests with a hash of your API secret, the called endpoint and parameters.

1. Activate ["Enforce Signed Header"](http://instagram.com/developer/clients/manage/) in your Instagram client settings.
2. Enable the signed-header in your Instagram class:

```
$instagram->setSignedHeader(true);
```

3. You are good to go! Now, all your requests will be secured with a signed header.

Go into more detail about how it works in the [Instagram API Docs](http://instagram.com/developer/restrict-api-requests/#enforce-signed-header).

Pagination
----------

[](#pagination)

Each endpoint has a maximum range of results, so increasing the `limit` parameter above the limit won't help (e.g. `getUserMedia()` has a limit of 90).

That's the point where the "pagination" feature comes into play. Simply pass an object into the `pagination()` method and receive your next dataset:

```
$photos = $instagram->getTagMedia('kitten');

$result = $instagram->pagination($photos);
```

Iteration with `do-while` loop.

> If you need further information about an endpoint, take a look at the [Instagram API docs](http://instagram.com/developer/authentication/).

Changelog
---------

[](#changelog)

Please see the [changelog file](CHANGELOG.md) for more information.

Released under the [BSD License](LICENSE).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3520d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c642bcbdec9d5400ef1dee14845681a886ace5c43cd80a6037daf919fdbe3505?d=identicon)[sofwar](/maintainers/sofwar)

---

Top Contributors

[![sofwar](https://avatars.githubusercontent.com/u/7130905?v=4)](https://github.com/sofwar "sofwar (12 commits)")

---

Tags

apiinstagram

### Embed Badge

![Health badge](/badges/sofwar-instagram/health.svg)

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

###  Alternatives

[jstolpe/instagram-graph-api-php-sdk

Instagram Graph API PHP SDK

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

PHPackages © 2026

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