espresso-dev / instagram-php
A simple PHP class for accessing the Instagram API
Installs: 1 299
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
README
A simple PHP wrapper for the Instagram API. Based on the original Instagram-PHP-API by Christian Metz
Composer package available.
Requirements
- PHP 5.6 or higher
- cURL
- Facebook Developer Account
- Facebook App
Get started
To use the Instagram API, you will need to register a Facebook app and configure Instagram Basic Display. Follow the getting started guide.
Installation
I strongly advise using Composer to keep updates as smooth as possible.
$ composer require espresso-dev/instagram-php
Initialize the class
use EspressoDev\Instagram\Instagram; $instagram = new Instagram([ 'appId' => 'YOUR_APP_ID', 'appSecret' => 'YOUR_APP_SECRET', 'redirectUri' => 'YOUR_APP_REDIRECT_URI' ]); echo "<a href='{$instagram->getLoginUrl()}'>Login with Instagram</a>";
Authenticate user (OAuth2)
// Get the OAuth callback code $code = $GET['code']; // Get the short lived access token (valid for 1 hour) $token = $instagram->getOAuthToken($code, true); // Exchange this token for a long lived token (valid for 60 days) $token = $instagram->getLongLivedToken($token, true); echo 'Your token is: ' . $token;
Get user profile
// Set user access token $instagram->setAccessToken($token); // Get the users profile $profile = $instagram->getUserProfile(); echo '<pre>'; print_r($profile); echo '</pre>';
Get user media
// Set user access token $instagram->setAccessToken($token); // Get the users media $media = $instagram->getUserMedia(); echo '<pre>'; print_r($media); echo '</pre>';