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

ActiveLibrary

romaricp/instagram
==================

The simple PHP Class for accessing Instagram's API

3.1.x-dev(9y ago)314PHPPHP &gt;=5.3.0

Since Jun 4Pushed 9y ago1 watchersCompare

[ Source](https://github.com/romaricp/api-instagram-with-php)[ Packagist](https://packagist.org/packages/romaricp/instagram)[ Docs](https://github.com/romaricp/api-instagram-with-php)[ RSS](/packages/romaricp-instagram/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Class PHP to use Instagram API v2 (2016)
========================================

[](#class-php-to-use-instagram-api-v2-2016)

> **Note:** On the 17 Nov 2015 [Instagram](http://developers.instagram.com/post/133424514006/instagram-platform-update) made [changes to their API ](https://instagram.com/developer/changelog/). Apps created before Nov 17, 2015 wont be affected until Jun 2016. Apps created on or after Nov 17 2015 will require to use their updated API. Please note that this library doesn't yet support their new updates.

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

[![Total Downloads](https://camo.githubusercontent.com/e390e2e990e70a524253f37ec781aeb496f14873bf21dace592d56f6e0b181bf/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f726f6d61726963702f696e7374616772616d2e7376673f7374796c653d666c6174)](https://packagist.org/packages/romaricp/instagram)[![Latest Stable Version](https://camo.githubusercontent.com/39ce9f906e481c94695fc31aecdcece5b5a83cc62e1c2b1b453f1105edbaa076/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6d61726963702f696e7374616772616d2e7376673f7374796c653d666c6174)](https://packagist.org/packages/romaricp/instagram)[![License](https://camo.githubusercontent.com/7948abda407b2f600b5b7f74e822c0a7b3583ffd34f2c8c9729d4ae45a9ef024/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f6d61726963702f696e7374616772616d2e7376673f7374796c653d666c6174)](https://packagist.org/packages/romaricp/instagram)

> [Composer](#installation) package available.
> Supports [Instagram Video](#instagram-videos) and [Signed Header](#signed-header).

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

[](#requirements)

- PHP 5.3 or higher
- cURL
- Registered Instagram App with new scope 2016

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`.

### Installation

[](#installation)

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

```
$ composer require romaricp/instagram

```

### Initialize the class

[](#initialize-the-class)

```
use RomaricP\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;
```

**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(
	'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'
));
```

**Optional scope parameters:**

  Scope Legend Methods   `basic` to use all user related methods \[default\] `getUser()`, `getUserFeed()`, `getUserFollower()` etc.   `relationships` to follow and unfollow users `modifyRelationship()`   `likes` to like and unlike items `getMediaLikes()`, `likeMedia()`, `deleteLikedMedia()`   `comments` to create or delete comments `getMediaComments()`, `addMediaComment()`, `deleteMediaComment()` ### 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)

**Public methods**

- `getUser($id)`
- `searchUser($name, )`
- `getUserMedia($id, )`

**Authenticated methods**

- `getUser()`
- `getUserLikes()`
- `getUserFeed()`
- `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)

**Authenticated methods**

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

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

---

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)

**Public methods**

- `getMedia($id)`
    - authenticated users receive the info, whether the queried media is liked
- `getPopularMedia()`
- `searchMedia($lat, $lng, , , )`
    - `$lat` and `$lng` are coordinates and have to be floats like: `48.145441892290336`,`11.568603515625`
    - `$distance` : Radial distance in meter (default is 1km = 1000, max. is 5km = 5000)
    - `$minTimestamp` : All media returned will be taken *later* than this timestamp (default: 5 days ago)
    - `$maxTimestamp` : All media returned will be taken *earlier* than this timestamp (default: now)

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

### Comment methods

[](#comment-methods)

**Public methods**

- `getMediaComments($id)`

**Authenticated methods**

- `addMediaComment($id, $text)`
    - **restricted access:** please email `apidevelopers[at]instagram.com` for access
- `deleteMediaComment($id, $commentID)`
    - the comment must be authored by the authenticated user

---

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)

**Public 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)`

> How to like a Media: [Example usage](https://gist.github.com/3287237)[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.

Instagram videos
----------------

[](#instagram-videos)

Instagram entries are marked with a `type` attribute (`image` or `video`), that allows you to identify videos.

An example of how to embed Instagram videos by using [Video.js](http://www.videojs.com), can be found in the `/example` folder.

---

**Please note:** Instagram currently doesn't allow to filter videos.

---

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.

Samples for redirect URLs
-------------------------

[](#samples-for-redirect-urls)

  Registered Redirect URI Redirect URI sent to /authorize Valid?     yes     yes     no    [http://yourcallback.com/?this=that&amp;another=true](http://yourcallback.com/?this=that&another=true) yes    [http://yourcallback.com/?another=true&amp;this=that](http://yourcallback.com/?another=true&this=that) no     no     yes > If you need further information about an endpoint, take a look at the [Instagram API docs](http://instagram.com/developer/authentication/).

> Let me know if you have to share a code example, too.

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

Copyright (c) 2011-2015 - Programmed by Christian Metz Released under the [BSD License](LICENSE).

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity45

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

Every ~284 days

Total

2

Last Release

3341d ago

### Community

---

Top Contributors

[![romaricp](https://avatars.githubusercontent.com/u/2545417?v=4)](https://github.com/romaricp "romaricp (8 commits)")

### Embed Badge

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

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

PHPackages © 2026

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