Exemple #1
0
require_once __DIR__ . '/autoload.php';
session_start();
$eyeem = new Eyeem();
$eyeem->setClientId(EYEEM_CLIENT_ID);
$eyeem->setClientSecret(EYEEM_CLIENT_SECRET);
// Sign Out
if (isset($_GET['signout'])) {
    unset($_SESSION['token']);
    header('Location:' . Eyeem_Utils::getCurrentUrl(array('signout')));
    exit;
    // oAuth callback
} else {
    if (isset($_GET['code'])) {
        $_SESSION['token'] = $token = $eyeem->getToken($_GET['code']);
        $eyeem->setAccessToken($token['access_token']);
        header('Location:' . Eyeem_Utils::getCurrentUrl(array('code', 'state')));
        exit;
        // Authenticated
    } else {
        if (!empty($_SESSION['token']['access_token'])) {
            $eyeem->setAccessToken($_SESSION['token']['access_token']);
        }
    }
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>EyeEm Client - Example</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"/>
Exemple #2
0
 public function getToken($code, $redirect_uri = null)
 {
     if (empty($redirect_uri)) {
         $redirect_uri = Eyeem_Utils::getCurrentUrl(array('code'));
     }
     $params = array('code' => $code, 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), 'grant_type' => 'authorization_code', 'redirect_uri' => $redirect_uri);
     $url = $this->getApiUrl('/oauth/token') . '?' . http_build_query($params);
     $response = Eyeem_Http::get($url);
     $token = json_decode($response, true);
     if (isset($token['error'])) {
         throw new Exception($token['error_description']);
     }
     return $token;
 }