A simple PHP wrapper for the Instagram API. Based on the original Instagram-PHP-API by Christian Metz
Composer package available.
- PHP 5.6 or higher
- cURL
- Facebook Developer Account
- Facebook App
To use the Instagram API, you will need to register a Facebook app and configure Instagram Basic Display. Follow the getting started guide.
I strongly advise using Composer to keep updates as smooth as possible.
$ composer require espresso-dev/instagram-phpuse 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>";// 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;// Set user access token
$instagram->setAccessToken($token);
// Get the users profile
$profile = $instagram->getUserProfile();
echo '<pre>';
print_r($profile);
echo '</pre>';// Set user access token
$instagram->setAccessToken($token);
// Get the users media
$media = $instagram->getUserMedia();
echo '<pre>';
print_r($media);
echo '</pre>';