kozz / instagram-client
Instagram 客户端
1.0.0
2015-07-17 12:27 UTC
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-09-14 17:53:34 UTC
README
安装并运行测试
composer install
vendor/bin/phpunit
# with coverage
vendor/bin/phpunit --coverage-html=build/logs
使用方法
OAuth
步骤 1
$client = new InstagramAuth(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "https:///auth")); $url = $client->getOAuthUrl(); // $url === 'https://api.instagram.com/oauth/authorize/?client_id=d2cbeff4792242f7b49ea65f984a1237&response_type=code&redirect_uri=https:///auth&scopes=basic
步骤 2
$client = new InstagramAuth(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "https:///auth")); $token = $client->retrieveOAuthToken($_GET['code']);
订阅
创建订阅
步骤 1
创建公共控制器和动作,该动作将处理 GET 请求。Instagram 在创建订阅时会调用它
class SomeController{ function actionCallbackGet{ echo $_GET['hub.challenge']; } }
步骤 1 创建订阅
$client = new InstagramClientUnauthorized(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "https:///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"), "https:///auth")); /** @var GetSubscriptionsResponse $response */ $response = $client->call(new GetSubscriptionsRequest());
删除订阅(s)
$client = new InstagramClientUnauthorized(new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "https:///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 ]));
处理来自 Instagram 的订阅请求
$config = new AuthConfig(env("I_CLIENT_ID"), env("I_CLIENT_SECRET"), "https:///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"