PHP User::readWithProvider Examples

PHP User::readWithProvider - 2 examples found. These are the top rated real world PHP examples of User::readWithProvider extracted from open source projects. You can rate examples to help us improve the quality of examples.
$access_token = $_SESSION['access_token'];
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
/* If method is set change API call made. Test is called by default. */
$user = $connection->get("account/verify_credentials");
/*
echo "<pre>";
var_dump($user);
echo "</pre>";
*/
// Let's find the user by its ID
$result = User::readWithProvider('twitter', $user->id);
// If not, let's add it to the database
if (empty($result)) {
    User::createWithProvider('twitter', $user->id, $user->screen_name, $access_token['oauth_token'], $access_token['oauth_token_secret']);
    $result = User::readWithProvider('twitter', $user->id);
} else {
    // Update the tokens
    User::updateWithProvider($access_token['oauth_token'], $access_token['oauth_token_secret'], 'twitter', $user->id);
    $result = User::readWithProvider('twitter', $user->id);
}
$_SESSION['id'] = $result->id;
$_SESSION['username'] = $result->username;
$_SESSION['oauth_uid'] = $result->oauth_uid;
$_SESSION['oauth_provider'] = $result->oauth_provider;
$_SESSION['oauth_token'] = $result->oauth_token;
$_SESSION['oauth_secret'] = $result->oauth_secret;
if (!empty($_SESSION['username'])) {
    // User is logged in, redirect
    header('Location: index.php');
}
Example #2
0
<?php

require 'user.php';
echo "<pre>";
var_dump(User::readWithProvider(1, 2));
echo "</pre>";