PHP code example of kozz / instagram-client

1. Go to this page and download the library: Download kozz/instagram-client 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/ */

    

kozz / instagram-client example snippets


$client = new InstagramAuth(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth"));
$url    = $client->getOAuthUrl();

// $url === 'https://api.instagram.com/oauth/authorize/?client_id=d2cbeff4792242f7b49ea65f984a1237&response_type=code&redirect_uri=http://localhost/auth&scopes=basic

$client = new InstagramAuth(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth"));
$token  = $client->retrieveOAuthToken($_GET['code']);


class SomeController{
    function actionCallbackGet{
        echo $_GET['hub.challenge'];
    }
}

$client = new InstagramClientUnauthorized(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth"));

/** @var CreateSubscriptionResponse $response */
$response = $client->call(new CreateSubscriptionRequest([
    'object' => 'user',
    'aspect' => 'media',
    'callback_url' => 'http://yoursite.me/some/callback'
]));



$client = new InstagramClientUnauthorized(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth"));
/** @var GetSubscriptionsResponse $response */
$response = $client->call(new GetSubscriptionsRequest());



$client = new InstagramClientUnauthorized(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth"));
/** @var DeleteSubscriptionsResponse $response */
$response = $client->call(new DeleteSubscriptionsRequest([
    'object'=>'user'
]));
$response = $client->call(new DeleteSubscriptionsRequest([
    'object'=>'all'
]));
$response = $client->call(new DeleteSubscriptionsRequest([
    'id'=>1
]));


$config  = new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "http://localhost/auth");
$reactor = new SubscriptionReactor($config);
$reactor->registerCallback("user", function(RealTimeSubscription $subscription){
    // Do something
});

$reactor->process($this->json, $_SERVER['HTTP_X_HUB_SIGNATURE']);
// $_SERVER['HTTP_X_HUB_SIGNATURE'] - it is just header "X-Hub-Signature"