espresso-dev / instagram-php
访问Instagram API的简单PHP类
v1.0
2024-09-23 17:41 UTC
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
README
Instagram API的简单PHP封装。基于Instagram-PHP-API,由Christian Metz创建
提供Composer包。
要求
- PHP 5.6或更高版本
- cURL
- Facebook开发者账户
- Facebook应用
开始使用
要使用Instagram API,您需要注册一个Facebook应用并配置Instagram基本显示。请遵循入门指南。
安装
强烈建议使用Composer以尽可能平滑地更新。
$ composer require espresso-dev/instagram-php
初始化类
use EspressoDev\Instagram\Instagram; $instagram = new Instagram([ 'appId' => 'YOUR_APP_ID', 'appSecret' => 'YOUR_APP_SECRET', 'redirectUri' => 'YOUR_APP_REDIRECT_URI' ]); echo "<a href='{$instagram->getLoginUrl()}'>Login with Instagram</a>";
用户认证(OAuth2)
// Get the OAuth callback code $code = $GET['code']; // Get the short lived access token (valid for 1 hour) $token = $instagram->getOAuthToken($code, true); // Exchange this token for a long lived token (valid for 60 days) $token = $instagram->getLongLivedToken($token, true); echo 'Your token is: ' . $token;
获取用户资料
// Set user access token $instagram->setAccessToken($token); // Get the users profile $profile = $instagram->getUserProfile(); echo '<pre>'; print_r($profile); echo '</pre>';
获取用户媒体
// Set user access token $instagram->setAccessToken($token); // Get the users media $media = $instagram->getUserMedia(); echo '<pre>'; print_r($media); echo '</pre>';