noprotocol / socialcast
此包最新版本(0.2)没有提供许可证信息。
Socialcast REST API 的 PHP 客户端
0.2
2014-05-26 07:57 UTC
Requires
This package is auto-updated.
Last update: 2024-09-17 21:33:57 UTC
README
Socialcast REST API 的 PHP 客户端
示例
使用基本身份验证
$auth = new Socialcast\Auth\BasicAuth('demo', 'emily@socialcast.com', 'demo'); $socialcast = new Socialcast\Client($auth); $user = $socialcast->getUserinfo(); $messages = $user->getMessages(['page' => 1, 'per_page' => 25]); var_dump($messages);
使用 OAuth 2.0 身份验证
session_start(); $oauth = new Socialcast\Auth\OAuth('demo', $appId, $secret, $callbackUrl, function () { return $_SESSION['socialcast']; }, function ($token) { $_SESSION['socialcast'] = $token; }); // On the callback url page: if (isset($_GET['code']) { $oauth->authenticate($_GET['code']); $socialcast = new Socialcast\Client($auth); if ($socialcast->getUserinfo()->id) { header('Location: /logged-in'); exit(); } echo 'Authentication failed: <a href="'.$oauth->getLoginUrl().''">retry</a>'; } else { header('Location: '.$oauth->getLoginUrl()); }
资源是懒加载的
为了最小化 API 请求的数量,资源对象(如用户资源)是懒加载的。
例如: $user = $socialcast->getUser(123);
在访问属性之前不会进行任何 API 请求。 var_dump($user); // 显示 #response: false. $id = $user->id var_dump($user); // 显示 #response: 包含数据的数组。