PHPackages                             league/oauth2-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. league/oauth2-instagram

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

league/oauth2-instagram
=======================

Instagram OAuth 2.0 Client Provider for The PHP League OAuth2-Client

3.1.0(4y ago)761.0M—4.6%22[1 issues](https://github.com/thephpleague/oauth2-instagram/issues)20MITPHP

Since Apr 8Pushed 2y ago7 watchersCompare

[ Source](https://github.com/thephpleague/oauth2-instagram)[ Packagist](https://packagist.org/packages/league/oauth2-instagram)[ RSS](/packages/league-oauth2-instagram/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (11)Used By (20)

Instagram Provider for OAuth 2.0 Client
=======================================

[](#instagram-provider-for-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/0b32c4be53ea7b1c28cd583598f46c25a8a67330e3e9a6210acde5f291aa1293/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7468657068706c65616775652f6f61757468322d696e7374616772616d2e7376673f7374796c653d666c61742d737175617265)](https://github.com/thephpleague/oauth2-instagram/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/7df902e5d5914e51f1cd28d87c02f9c3955583fa7d2ae48c6c4e8754943dc283/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f6f61757468322d696e7374616772616d2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/oauth2-instagram)[![Coverage Status](https://camo.githubusercontent.com/402263b285143d069ba23bca9d0f2f98731aecf99d71ee4dc65ae42affe16144/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f6f61757468322d696e7374616772616d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/oauth2-instagram/code-structure)[![Quality Score](https://camo.githubusercontent.com/8b602c0d4c20c3a08bf27cb4d48379a6ffa0bfe74a09846f72ada3b702724c3d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f6f61757468322d696e7374616772616d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/oauth2-instagram)[![Total Downloads](https://camo.githubusercontent.com/6c89777488d278a89fa88a132a7fb94aeaab09429807f16338f1c4e2167cef77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f6f61757468322d696e7374616772616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/oauth2-instagram)

This package provides Instagram OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

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

[](#installation)

To install, use composer:

```
composer require league/oauth2-instagram

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\League\OAuth2\Client\Provider\Instagram` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new League\OAuth2\Client\Provider\Instagram([
    'clientId'          => '{instagram-client-id}',
    'clientSecret'      => '{instagram-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
    'host'              => 'https://api.instagram.com',  // Optional, defaults to https://api.instagram.com
    'graphHost'         => 'https://graph.instagram.com' // Optional, defaults to https://graph.instagram.com
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getNickname());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

### Requesting a long-lived access-token

[](#requesting-a-long-lived-access-token)

```
$token = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code']
]);

$longLivedToken = $provider->getLongLivedAccessToken($token);
```

### Refreshing a long-lived access-token

[](#refreshing-a-long-lived-access-token)

```
$token = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code']
]);

// you need to fetch a long-lived token first!
$longLivedToken = $provider->getLongLivedAccessToken($token);

$refreshedToken = $provider->getRefreshedAccessToken($longLivedToken);
```

### Managing Scopes

[](#managing-scopes)

When creating your Instagram authorization URL, you can specify the state and scopes your application may authorize.

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => ['user_profile', 'user_media'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the [following scopes are available](https://developers.facebook.com/docs/instagram-basic-display-api/overview#permissions).

- user\_profile
- user\_media

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/thephpleague/oauth2-instagram/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/thephpleague/oauth2-instagram/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth2-instagram/blob/master/LICENSE) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 66% 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 ~277 days

Recently: every ~531 days

Total

10

Last Release

1559d ago

Major Versions

0.2.3 → 2.0.02017-01-26

2.0.0 → 3.0.02020-02-25

PHP version history (2 changes)0.1.0PHP &gt;=5.4.0

0.2.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d9c05a30823ae19fc54aa4b4721a696c253f8dec10c7fd22d372cfdc0fcb36d?d=identicon)[stevenmaguire](/maintainers/stevenmaguire)

---

Top Contributors

[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (33 commits)")[![oddevan](https://avatars.githubusercontent.com/u/1427716?v=4)](https://github.com/oddevan "oddevan (5 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (4 commits)")[![acran](https://avatars.githubusercontent.com/u/4603809?v=4)](https://github.com/acran "acran (3 commits)")[![waltervos](https://avatars.githubusercontent.com/u/30372?v=4)](https://github.com/waltervos "waltervos (2 commits)")[![ramsey](https://avatars.githubusercontent.com/u/42941?v=4)](https://github.com/ramsey "ramsey (1 commits)")[![solverat](https://avatars.githubusercontent.com/u/700119?v=4)](https://github.com/solverat "solverat (1 commits)")[![ker0x](https://avatars.githubusercontent.com/u/5331654?v=4)](https://github.com/ker0x "ker0x (1 commits)")

---

Tags

clientinstagramoauthoauth2authorizationauthorisation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

GitLab OAuth 2.0 Client Provider for The PHP League OAuth2-Client

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

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