/**
  * @param string $id
  * @return User|null
  */
 public function getUser($id)
 {
     try {
         $cfUser = $this->cultureFeed->getUser($id, self::INCLUDE_PRIVATE_FIELDS);
         // Cast to a User object that can be safely encoded to json.
         return User::fromCultureFeedUser($cfUser);
     } catch (\CultureFeed_ParseException $e) {
         return null;
     }
 }
 // Fetch the authorisation url...
 $auth_url = $c->getUrlAuthorize($token, $callback_url, CultureFeed::AUTHORIZE_TYPE_REGULAR);
 print "Now open the following URL in your browser: {$auth_url}" . PHP_EOL;
 print "After logging in with your UiTID you should inspect your RequestBin and find there the last request with an oauth_token and oauth_verifier." . PHP_EOL;
 print "Make sure the you have identified the right request, containing the oauth token: {$token['oauth_token']}" . PHP_EOL;
 print "Give me the oauth_verifier value now: ";
 $oauth_verifier = fgets(STDIN);
 $oauth_verifier = trim($oauth_verifier);
 $user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
 $user_oauth_client->setEndpoint($endpoint);
 $user_c = new CultureFeed($user_oauth_client);
 $new_token = $user_c->getAccessToken($oauth_verifier);
 $new_user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $new_token['oauth_token'], $new_token['oauth_token_secret']);
 $new_user_oauth_client->setEndpoint($endpoint);
 $new_user_c = new CultureFeed($new_user_oauth_client);
 $account = $new_user_c->getUser($new_token['userId']);
 print "You have succesfully logged in with the following account: {$account->nick} [{$account->id}]" . PHP_EOL;
 print "Setting user preferences" . PHP_EOL;
 $preferences = new CultureFeed_Preferences();
 $preferences->activityPrivacyPreferences[] = new CultureFeed_ActivityPrivacyPreference(CultureFeed_Activity::TYPE_UITPAS, FALSE);
 $preferences = $new_user_c->setUserPreferences($account->id, $preferences);
 if (count($preferences->activityPrivacyPreferences) == 0) {
     print "No user preferences found" . PHP_EOL;
 } else {
     print "User preferences:" . PHP_EOL;
     foreach ($preferences->activityPrivacyPreferences as $preference) {
         $private = $preference->private ? "private" : "public";
         print "{$preference->activityType}: {$private}" . PHP_EOL;
     }
 }
 print "Getting user preferences" . PHP_EOL;
示例#3
0
$app['current_user'] = $app->share(function ($app) {
    /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
    $session = $app['session'];
    $config = $app['config']['uitid'];
    /** @var \CultuurNet\Auth\User $minimalUserData */
    $minimalUserData = $session->get('culturefeed_user');
    if ($minimalUserData) {
        /** @var \CultuurNet\Auth\ConsumerCredentials $consumerCredentials */
        $consumerCredentials = $app['uitid_consumer_credentials'];
        $userCredentials = $minimalUserData->getTokenCredentials();
        $oauthClient = new CultureFeed_DefaultOAuthClient($consumerCredentials->getKey(), $consumerCredentials->getSecret(), $userCredentials->getToken(), $userCredentials->getSecret());
        $oauthClient->setEndpoint($config['base_url']);
        $cf = new CultureFeed($oauthClient);
        try {
            $private = true;
            $user = $cf->getUser($minimalUserData->getId(), $private);
        } catch (\Exception $e) {
            return NULL;
        }
        unset($user->following);
        return $user;
    }
    return NULL;
});
$app['auth_service'] = $app->share(function ($app) {
    $uitidConfig = $app['config']['uitid'];
    return new CultuurNet\Auth\Guzzle\Service($uitidConfig['base_url'], $app['uitid_consumer_credentials']);
});
$app['cache-redis'] = $app->share(function (Application $app) {
    $parameters = $app['config']['cache']['redis'];
    return function ($cacheType) use($parameters) {
示例#4
0
date_default_timezone_set('Europe/Brussels');
// require the third-party oauth library which is not properly structured to be autoloaded
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
function culturefeed_autoload($class)
{
    $file = str_replace('_', '/', $class) . '.php';
    require_once $file;
}
spl_autoload_register('culturefeed_autoload');
try {
    $endpoint = $_SERVER['argv'][1];
    $consumer_key = $_SERVER['argv'][2];
    $consumer_secret = $_SERVER['argv'][3];
    $user_id = $_SERVER['argv'][4];
    $oc = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret);
    $oc->setEndpoint($endpoint);
    $c = new CultureFeed($oc);
    $user = $c->getUser($user_id, FALSE, FALSE);
    print_r($user);
} catch (Exception $e) {
    $eol = PHP_EOL;
    $type = get_class($e);
    print "An exception of type {$type} was thrown." . PHP_EOL;
    print "Code: {$e->getCode()}" . PHP_EOL;
    if ($e instanceof CultureFeed_Exception) {
        print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
    }
    print "Message: {$e->getMessage()}" . PHP_EOL;
    print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;
    exit(1);
}