espresso-dev / instagram-php
A simple PHP class for accessing the Instagram API
v1.1.2
2024-10-11 09:35 UTC
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>';