PHP code example of noprotocol / socialcast

1. Go to this page and download the library: Download noprotocol/socialcast library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

noprotocol / socialcast example snippets


$auth = new Socialcast\Auth\BasicAuth('demo', '[email protected]', 'demo');
$socialcast = new Socialcast\Client($auth);

$user = $socialcast->getUserinfo();
$messages = $user->getMessages(['page' => 1, 'per_page' => 25]);
var_dump($messages);

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());
}