PHPackages                             marketmesuite/php-instagram-api - 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. marketmesuite/php-instagram-api

ActiveLibrary[API Development](/categories/api)

marketmesuite/php-instagram-api
===============================

PHP Instagram API for PHP 5.3+

v0.1(12y ago)123MITPHPPHP &gt;=5.3.0

Since Feb 21Pushed 12y ago34 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

\#PHP Instagram API

This is a PHP 5.3+ API wrapper for the [Instagram API](http://instagram.com/developer/)

The API comes with a cURL client (`Instagram\Net\CurlClient`) to access the Instagran API. You can create your own client, it just has to implement `Instagram\Net\ClientInterface`.

---

\##The API

All methods that access the API can throw exceptions. If the API request fails for any reason other than an expired/missing access token an exception of type `\Instagram\Core\ApiException` will be thrown. If the API request fails because of an expired/missing access token an exception of type `\Instagram\Core\ApiAuthException` will be thrown. You can use this to redirect to your authorization page.

\##Authentication

- [Set up a client for use with Instagram's API](http://instagr.am/developer/clients/manage/)
- Create an Auth Object and pass in the information from the API

```
$auth_config = array(
    'client_id'         => '',
    'client_secret'     => '',
    'redirect_uri'      => '',
    'scope'             => array( 'likes', 'comments', 'relationships' )
);

$auth = new Instagram\Auth( $auth_config );

```

- Then you have to get the user to authorize your app

```
$auth->authorize();

```

- If you want to get the authorization URL, you should use this

```
$authUrl = $auth->getAuthorizationUrl();

```

- This will redirect the user to the Instagram authorization page. After authorization Instagram will redirect the user to the url in `$auth_config['redirect_uri']` with a code that you will need to obtain an access token

```
$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );

```

- Then use the access token in your code

```
$instagram = new Instagram\Instagram;
$instagram->setAccessToken( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();

```

\##Basic Usage

```
$instagram = new Instagram\Instagram( $_SESSION['instagram_access_token'] );
$user = $instagram->getUser( $user_id );
$media = $instagram->getMedia( $media_id );
$tag = $instagram->getTag( 'mariokart' );
$location = $instagram->getLocation( 3001881 );
$current_user = $instagram->getCurrentUser();

```

\##Current User

The current user object will give you the currently logged in user

```
$current_user = $instagram->getCurrentUser();

```

With this object you can:

- follow, unfollow, block, and unblock users

```
$current_user->follow( $user );
$current_user->unfollow( $user );
$current_user->block( $user );
$current_user->unblock( $user );

```

- obtain the user's feed, liked media, follow requests

```
$feed = $current_user->getFeed();
$liked_media = $current_user->getLikedMedia();

```

- ignore and approve follow requests

```
$current_user->ignoreFollowRequest( $user );
$current_user->approveFollowRequest( $user );

```

You can also perform all the functions you could on a normal user

\##Getting Media

Users, tags, locations, and the current user have media associated with them.

This will return recent media from the 4 objects:

```
$user->getMedia();
$tag->getMedia();
$location->getMedia();
$current_user->getMedia();

```

You can pass an array of parameters to `getMedia()`. These parameters will be passed directly to the API. Check the API for a list of available parameters.

```
$user->getMedia(
    array( 'count' => 3 )
);
$tag->getMedia(
    array( 'max_tag_id' => $max_tag_id )
);
$location->getMedia(
    array( 'max_id' => $max_id )
);

```

\##Images and Videos

You can distinguish between images and videos with `Media::getType()`. This will return `video` or `image`. Video files can be accessed with `Media::getStandardResVideo()` and `Media::getLowResVideo()`. The image methods on a video will return a still of the video.

\##Collections

When making a call to a method that returns more than one of something (e.g. getMedia(), searchUsers() ), a collection object will be returned. Collections can be iterated, counted, and accessed like arrays.

```
$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
foreach( $media as $photo ) {
     ...
}
$media_count = count( $media );
$first_photo = $media[0];

```

The collection object will sometimes have an identifier to the "next page" that can be used to obtain the next page of the collection.

To obtain the identifier for the next page you call `getNext()` on the collection object.

For example:

```
$user = $instagram->getUser( $user_id );
$media = $user->getMedia();
$next_page = $media->getNext();

```

Example usage:

```
