kozz/instagram-client

Instatram Client

1.0.0 2015-07-17 12:27 UTC

This package is not auto-updated.

Last update: 2024-11-09 18:43:23 UTC


README

Build Status Code Climate Test Coverage SensioLabsInsight

Install and run tests

composer install
vendor/bin/phpunit

# with coverage
vendor/bin/phpunit --coverage-html=build/logs

Usage

OAuth

Step 1

$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

Step 2

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

Subscriptions

Create Subscription

Step 1

Create public controller and action, which would handle GET request. Instagramm will call it during creating subscription:

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

Step 1 Create Subscription:

$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'
]));

Get subscriptions

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

Delete subscription(s)

$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
]));

Handle subscription request from the Instagram

$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"