maztech / instagram-php-graph-sdk
Instagram SDK for PHP
v1.0.3
2022-03-28 02:07 UTC
Requires
- php: ^5.4|^7.0
Requires (Dev)
- guzzlehttp/guzzle: ~5.0
- mockery/mockery: ~0.8
- phpunit/phpunit: ~4.0
Suggests
- guzzlehttp/guzzle: Allows for implementation of the Guzzle HTTP client
- paragonie/random_compat: Provides a better CSPRNG option in PHP 5
README
This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app.
Disclamer: This SDK using Instagram Graph API and encourage to use "Instagram Basic Display API".
Requirement
- PHP >=5.4.1
- Guzzle 5.x
- PHPunit 4.x
- mockery 0.8
Installation
The preferred installation method is via composer. You can add the library as a dependency via:
$ composer require maztech/instagram-php-graph-sdk
Usage
<?php require_once __DIR__ . '/vendor/autoload.php'; // change path as needed $ig = new \Maztech\Instagram([ 'app_id' => '{app-id}', 'app_secret' => '{app-secret}' ]); // Use one of the helper classes to get a Instagram\Authentication\AccessToken entity. $helper = $ig->getRedirectLoginHelper(); // instagram login - https://api.instagram.com/oauth/authorize?app_id={$clientId}&redirect_uri={$redirecUri}&scope=user_profile,user_media&response_type=code $helper->getLoginUrl(); // get authorization url // instagram callback $helper->getAccessToken(); // get access token from code try { $queryParams = http_build_query([ 'access_token' => '{access-token}' ]); $response = $ig->get('/me?{$queryParams}'); } catch(\Instagram\Exceptions\InstagramResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(\Instagram\Exceptions\InstagramSDKException $e) { // When validation fails or other local issues echo 'Instagram SDK returned an error: ' . $e->getMessage(); exit; }
This SDK was referred at Facebook Developer site here
Copyright & License
PHP SDK for Instagram Graph API is Copyright (c) 2022 Mohd Azmin if not otherwise stated. The code is distributed under the terms of the MIT License.