kozz / instagram-client
Instatram Client
Installs: 208
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Type:project
Requires
- doctrine/common: ~2.5
- guzzlehttp/guzzle: ~6.0
- jms/serializer: ~0.16
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mockery/mockery: ~0.9.0
- phpspec/phpspec: ~2.1
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-09 18:43:23 UTC
README
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"