noprotocol / socialcast
There is no license information available for the latest version (0.2) of this package.
PHP Client for Socialcast’s REST API
0.2
2014-05-26 07:57 UTC
Requires
This package is auto-updated.
Last update: 2024-10-17 21:41:17 UTC
README
PHP client for Socialcast’s REST API
Examples
Using Basic Authentication
$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);
Using OAuth 2.0 Authentication
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()); }
Resources are Lazy
To minimize the amount of api request the Resource objects such as the User resource are loaded lazily.
For example: $user = $socialcast->getUser(123);
doesn't make any api calls until a property is accessed.
var_dump($user); // shows #response: false.
$id = $user->id
var_dump($user); // shows #response: array with data.