PHP code example of maztech / instagram-php-graph-sdk

1. Go to this page and download the library: Download maztech/instagram-php-graph-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maztech / instagram-php-graph-sdk example snippets



= 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;
}