Created: 2012-03-24 23:50
Updated: 2018-11-24 18:55


This is a very lightweight PHP Instagram API Library that I've created to test the API. It is very simple and it works, it may not be the best thing to use in production though.

Required libraries

All requirements are set in the composer.json

How to use

Quick Start

Create an instance of the Instagram object using you Instagram App information.

It is important that the callback_uri to match the one you set up in the app setting or the oauth login url will fail.

use Instagram\Instagram;

$instagram = new Instagram('client_id', 'client_secret', 'callback_uri');

Set an Access Token

$instagram->setAccessToken('Access Token');

Generic request

Create a request to any API endpoint.

The generic method lets you request an endpoint and add parameters to the request.


 //recent photos with the hasthag love
$content = $instagram->generic('/tags/love/media/recent');

//liked photos for the user set with the access token
$content = $instagram->generic('/users/self/media/liked');

//search for users by username
$content = $instagram->generic('/users/search', ['q' => 'aseba']);

//get recent media from user
$content = $instagram->generic('user/media/recent');


We've created two helper methods to make comment processing easier


Use the comment requests to post a message as a comment in an instagram

Link to the documentation in Instagram

$response = $instagram->comment($media_id, $message);


Remove a comment of an instagram

Link to the documentation in Instagram

$response = $instagram->delete_comment($media_id, $comment_id);



You can use getLogin() to get the url to take the user to start the oauth process.

$instagram->getLogin('response type', [scopes]));
  • Response Type is set to code by default.
  • scopes is empty by default.


$instagram->getLogin('token', ['basic','public_content','comments', 'relationships', 'follower_list']));

Signed requests

If your app requires signed requests you can use the $instagram->sign() to start signing all requests to Instagram.

Full working example



require __DIR__.'/vendor/autoload.php';

use Instagram\Instagram;

$instagram = new Instagram('client_id', 'client_secret', 'callback_uri');
$instagram->setAccessToken('Access Token');
$content = $instagram->generic('tags/love/media/recent');

foreach($content->data as $media) {
  echo($media->caption->text . "\n");
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more