maztech / instagram-php-graph-sdk
PHP Instagram SDK
v1.0.3
2022-03-28 02:07 UTC
Requires
- php: ^5.4|^7.0
Requires (Dev)
- guzzlehttp/guzzle: ~5.0
- mockery/mockery: ~0.8
- phpunit/phpunit: ~4.0
Suggests
- guzzlehttp/guzzle: Allows for implementation of the Guzzle HTTP client
- paragonie/random_compat: Provides a better CSPRNG option in PHP 5
README
此仓库包含一个开源PHP SDK,允许您从PHP应用程序访问Facebook平台。
免责声明:此SDK使用Instagram Graph API,并鼓励使用"Instagram Basic Display API"。
要求
- PHP >=5.4.1
- Guzzle 5.x
- PHPunit 4.x
- mockery 0.8
安装
首选的安装方法是使用composer。您可以通过以下方式将库作为依赖项添加:
$ composer require maztech/instagram-php-graph-sdk
使用方法
<?php require_once __DIR__ . '/vendor/autoload.php'; // change path as needed $ig = 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; }
此SDK在Facebook开发者网站上有所介绍 此处
版权 & 许可证
Instagram Graph API的PHP SDK版权(c)2022 Mohd Azmin,除非另有说明。代码根据MIT许可证分发。