本文整理汇总了PHP中TwitterOAuth::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth::getAccessToken方法的具体用法?PHP TwitterOAuth::getAccessToken怎么用?PHP TwitterOAuth::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth::getAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callBack
public function callBack()
{
/* If the oauth_token is old redirect to the connect page. */
// if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token'])
if (isset($_REQUEST['oauth_token']) && $this->session->userdata('oauth_token') !== $_REQUEST['oauth_token']) {
// $_SESSION['oauth_status'] = 'oldtoken';
// header('Location: ./clearsessions.php');
echo "bad oauth_token";
return false;
}
/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(_TWITTER_CONSUMER_KEY_, _TWITTER_CONSUMER_SECRET_, $this->session->userdata('oauth_token'), $this->session->userdata('oauth_token_secret'));
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
/* Save the access tokens. Normally these would be saved in a database for future use. */
$_SESSION['access_token'] = $access_token;
$this->db_update("users", $access_token, array("id" => $this->session->userdata('id')));
// /* Remove no longer needed request tokens */
// unset($_SESSION['oauth_token']);
// unset($_SESSION['oauth_token_secret']);
/* If HTTP response is 200 continue otherwise send to connect page to retry */
if (200 == $connection->http_code) {
/* The user has been verified and the access tokens can be saved for future use */
// $_SESSION['status'] = 'verified';
// header('Location: ./index.php');
echo "TWITTER OK";
} else {
/* Save HTTP status for error dialog on connnect page.*/
// header('Location: ./clearsessions.php');
echo "ERROR";
}
}
示例2: getUserAccessToken
function getUserAccessToken()
{
$session_access_token = $this->constructSessionVariableName("access_token");
$token = NULL;
if (isset($_SESSION[$session_access_token])) {
$token = $_SESSION[$session_access_token];
if (!$token || !isset($token["oauth_token"])) {
unset($_SESSION[$session_access_token]);
}
}
if (!$token) {
$session_request_token = $this->constructSessionVariableName("oauth_request_token");
$session_request_token_secret = $this->constructSessionVariableName("oauth_request_token_secret");
if (isset($_SESSION[$session_request_token]) && isset($_SESSION[$session_request_token_secret])) {
$to = new TwitterOAuth($this->getTwitter()->consumer->key, $this->getTwitter()->consumer->secret, $_SESSION[$session_request_token], $_SESSION[$session_request_token_secret]);
$token = $to->getAccessToken($_REQUEST['oauth_verifier']);
if (!$token || !isset($token["oauth_token"])) {
unset($_SESSION[$session_request_token]);
unset($_SESSION[$session_request_token_secret]);
} else {
$session_var_name = $this->constructSessionVariableName("access_token");
$_SESSION[$session_var_name] = $token;
}
}
}
return $token;
}
示例3: initComment
public static function initComment($api)
{
session_start();
$options = Typecho_Widget::widget('Widget_Options');
$config = $options->plugin('ConnectToTwitter');
//发送请求到twitter
if (isset($api->request->connect_to_twitter)) {
$to = new TwitterOAuth($config->consumerKey, $config->consumerSecret);
$tok = $to->getRequestToken();
Typecho_Cookie::set('oauth_request_token', $tok['oauth_token']);
Typecho_Cookie::set('oauth_request_token_secret', $tok['oauth_token_secret']);
/* Build the authorization URL */
$request_link = $to->getAuthorizeURL($tok['oauth_token']);
header('Location:' . $request_link);
}
//从twitter返回
if (isset($api->request->oauth_token)) {
if (Typecho_Cookie::get('oauth_request_token') && Typecho_Cookie::get('oauth_request_token_secret')) {
$to = new TwitterOAuth($config->consumerKey, $config->consumerSecret, Typecho_Cookie::get('oauth_request_token'), Typecho_Cookie::get('oauth_request_token_secret'));
$tok = $to->getAccessToken();
Typecho_Cookie::set('oauth_access_token', $tok['oauth_token'], time() + 60 * 60 * 24 * 30);
Typecho_Cookie::set('oauth_access_token_secret', $tok['oauth_token_secret'], time() + 60 * 60 * 24 * 30);
$info_json = $to->OAuthRequest('https://twitter.com/account/verify_credentials.json', array(), 'GET');
$info = Typecho_Json::decode($info_json, true);
self::twitterLogin($info, $api);
}
}
}
示例4: add_new_account
/**
* Used to add new record to Access Tokens Table
*
* @access public
*
* @param $oauth_verifier - $_REQUEST['code'] from controller
* @param $profile_id
*
* @return string
* @throws Exception
*/
public function add_new_account($oauth_verifier, $profile_id)
{
$oauth_token = $this->_ci->session->userdata('oauth_token');
$oauth_token_secret = $this->_ci->session->userdata('oauth_token_secret');
$connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret'], $oauth_token, $oauth_token_secret);
$token_credentials = $connection->getAccessToken($oauth_verifier);
$tokens = array('token' => $token_credentials['oauth_token'], 'secret_token' => $token_credentials['oauth_token_secret']);
try {
if (empty($this->_user_id)) {
throw new Exception("There in no active user to connect to twitter.");
}
$tokens['username'] = $token_credentials['screen_name'];
$socialFullInfo = $this->get_user_full_info($tokens['username']);
if (empty($socialFullInfo->name)) {
throw new Exception("Invalid twitter's user data. Please try to reconnect.");
}
$tokens['name'] = $socialFullInfo->name;
$tokens['image'] = $socialFullInfo->profile_image_url;
$access_token = new Access_token();
$token = $access_token->add_token($tokens, 'twitter', $this->_user_id);
if (!$token->exists()) {
throw new Exception("Cant save twitter access data. Please try to reconnect.");
}
$social_group = new Social_group($profile_id);
$social_group->save(array('access_token' => $token));
} catch (Exception $e) {
throw $e;
}
$redirect_url = site_url('settings/socialmedia');
return $redirect_url;
}
示例5: authTwitter
protected function authTwitter($save_name)
{
$config = $this->config;
$conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret']);
$request_token = $conn->getRequestToken();
if ($request_token === false || $conn->lastStatusCode() != 200) {
throw new RuntimeException("Error fetching Twitter auth token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
}
$url = $conn->getAuthorizeURL($request_token);
// Automatically send the user to the auth page.
$ui = new UI();
$ui->openBrowser($url);
$pin = $ui->readline("Please visit {$url} then type the pin number: ");
$conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret'], $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = $conn->getAccessToken($pin);
if ($access_token === false || $conn->lastStatusCode() != 200) {
throw new RuntimeException("Error fetching Twitter access token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
}
$this->config['oauth_token'] = $access_token['oauth_token'];
$this->config['oauth_token_secret'] = $access_token['oauth_token_secret'];
echo "Your Twitter token is " . $access_token['oauth_token'] . "\n";
echo "Your Twitter token secret is " . $access_token['oauth_token_secret'] . "\n";
echo "(Written to twitter-{$save_name}.txt)\n";
if (file_put_contents("twitter-{$save_name}.txt", $access_token['oauth_token'] . "\n" . $access_token['oauth_token_secret'])) {
return;
}
throw new RuntimeException("Failed to save oauth token to twitter-{$save_name}.txt");
}
示例6: getToken
public static function getToken($oauthToken, $oauthTokenSecret, $oauthVerifier)
{
list($consumerKey, $consumerSecret) = bdSocialShare_Option::getTwitterConsumerPair();
$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$token = $twitter->getAccessToken($oauthVerifier);
return $token;
}
示例7: callback
/**
* Verify credentials and redirect based on response from Twitter.
*/
public function callback()
{
require_once MODPATH . "twitter/vendor/twitteroauth/twitteroauth.php";
$consumer_key = module::get_var("twitter", "consumer_key");
$consumer_secret = module::get_var("twitter", "consumer_secret");
$oauth_token = Session::instance()->get("twitter_oauth_token");
$oauth_token_secret = Session::instance()->get("twitter_oauth_token_secret");
$item_url = Session::instance()->get("twitter_item_redirect");
// If the oauth_token is old redirect to the connect page
if (isset($_REQUEST['oauth_token']) && $oauth_token !== $_REQUEST['oauth_token']) {
Session::instance()->set("twitter_oauth_status", "old_token");
$this->_clear_session();
url::redirect(url::site("twitter/redirect"));
}
// Create TwitteroAuth object with app key/secret and token key/secret from default phase
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
// Request access tokens from twitter
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
// Save the access tokens
Session::instance()->set("twitter_access_token", $access_token);
// Remove no longer needed request tokens
Session::instance()->delete("twitter_oauth_token");
Session::instance()->delete("twitter_oauth_token_secret");
// If HTTP response is 200 continue otherwise send to connect page to retry
if (200 == $connection->http_code) {
$this->_save_user($access_token);
$item = ORM::factory("item", $item_id);
url::redirect(url::abs_site($item_url));
} else {
log::error("content", "Twitter", "Unable to retrieve user access token: " . $connection->http_code);
$this->_clear_session();
url::redirect(url::site("twitter/redirect"));
}
}
示例8: getMe
/**
* Return info about login user
* @param $oauthToken
* @param $oauthVerifier
* @return \API|mixed
* @throws Exception
*/
public function getMe($oauthToken, $oauthVerifier)
{
$sessionSection = $this->session->getSection("twitter");
if ($oauthToken != "" && $sessionSection->oauth_token !== $oauthToken) {
//$sessionSection->oauth_status = 'oldtoken';
throw new Exception("Twitter token is old. Try again login");
}
//Create TwitteroAuth object with app key/secret and token key/secret from default phase
$this->twitterOAuth = new \TwitterOAuth($this->params["consumerKey"], $this->params["consumerSecret"], $sessionSection->oauth_token, $sessionSection->oauth_token_secret);
//Request access tokens from twitter
$access_token = $this->twitterOAuth->getAccessToken($oauthVerifier);
//Save the access tokens
$sessionSection->access_token = $access_token;
// Remove no longer needed request tokens
unset($sessionSection->oauth_token);
unset($sessionSection->oauth_token_secret);
if (200 != $this->twitterOAuth->http_code) {
//Save HTTP status for error dialog on connnect page.
throw new Exception("Twitter login. Something is wrong");
}
//The user has been verified
//$sessionSection->status = 'verified';
$user_info = $this->twitterOAuth->get('account/verify_credentials');
$this->setSocialLoginCookie(self::SOCIAL_NAME);
return $user_info;
}
示例9: test
public function test()
{
$aModel = TuiyoLoader::model("applications", true);
$aUser = TuiyoAPI::get("user", null);
$aDocument = TuiyoAPI::get("document", null);
$aParams = $aModel->getSingleUserPlugin($aUser->id, "twitter");
if (!is_object($aParams)) {
$aDocument->enqueMessage(_("Cannot Load the service for this user"), "error");
return false;
}
echo $aParams->get("oauth_verifier");
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$view =& $this->getView("twitter", "html");
/* Get temporary credentials. */
$access_token = $connection->getAccessToken($aParams->get('oauth_verifier', false));
/* 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. */
$content = $connection->get('account/verify_credentials');
//print_R($content);
$user = $connection->get('account/verify_credentials');
$userPublicFeeds = $connection->get('statuses/public_timeline');
print_R($userPublicFeeds);
}
示例10: twitter_login
public function twitter_login()
{
$a = $this->session->userdata('token');
if ($a) {
$connection = new TwitterOAuth('NXN5bPRLh6npCLauKil2FMoq5', '4aWzIN9yuV80f16odPxkFKeWftwkvGeVjbBt9sTPYyfCaUb4sf', $this->session->userdata('token'), $this->session->userdata('token_secret'));
if (!empty($_REQUEST['oauth_verifier'])) {
$oauth_verifier = $_REQUEST['oauth_verifier'];
} else {
redirect('auth/log_out');
}
$access_token = $connection->getAccessToken($oauth_verifier);
$data = array('id' => $access_token['user_id'], 'first_name' => $access_token['screen_name'], 'last_name' => $access_token['screen_name'], 'isLogged' => TRUE, 'role' => 0);
$this->session->set_userdata($data);
$twiter_users = $this->users_model->get_record_by_filed(array('id' => $access_token['user_id']));
if (count($twiter_users) == 0) {
$last_id = $this->users_model->insert_data($data);
} else {
$last_id = $this->users_model->get_record(array('id' => $access_token['user_id']));
$this->users_model->update_record($last_id->id, $data);
}
redirect('frontend/home');
} else {
$connection = new TwitterOAuth('NXN5bPRLh6npCLauKil2FMoq5', '4aWzIN9yuV80f16odPxkFKeWftwkvGeVjbBt9sTPYyfCaUb4sf');
$request_token = $connection->getRequestToken('http://shop.loc/auth/twitter_login');
$data = array('token' => $request_token['oauth_token'], 'token_secret' => $request_token['oauth_token_secret']);
$this->session->set_userdata($data);
if ($connection->http_code == '200') {
$twitter_url = $connection->getAuthorizeURL($request_token['oauth_token']);
header('Location: ' . $twitter_url);
} else {
die("error connecting to twitter! try again later!");
}
}
}
示例11: index
function index()
{
require APPPATH . 'modules/twitter/libraries/twitteroauth.php';
/* If the oauth_token is old redirect to the connect page. */
if ($this->input->get('oauth_token') && $this->session->userdata('twitter_oauth_token') !== $this->input->get('oauth_token')) {
return redirect('admincp/twitter');
}
/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(setting('twitter_consumer_key'), setting('twitter_consumer_secret'), $this->session->userdata('twitter_oauth_token'), $this->session->userdata('twitter_oauth_token_secret'));
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($this->input->get('oauth_verifier'));
/* Save the access tokens. Normally these would be saved in a database for future use. */
$this->settings_model->update_setting('twitter_oauth_token', $access_token['oauth_token']);
$this->settings_model->update_setting('twitter_oauth_token_secret', $access_token['oauth_token_secret']);
/* Remove no longer needed request tokens */
$this->session->unset_userdata('twitter_oauth_token');
$this->session->unset_userdata('twitter_oauth_token_secret');
/* If HTTP response is 200 continue otherwise send to connect page to retry */
if (200 == $connection->http_code) {
$this->notices->SetNotice('OAuthorization retrieved successfully.');
return redirect('admincp/twitter');
} else {
$this->notices->SetError('Error making connection in OAuth callback.');
return redirect('admincp/twitter');
}
}
示例12: twittercallback
function twittercallback()
{
$twitter = new TwitterOAuth(TWITTER_APIKEY, TWITTER_APISECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$token = $twitter->getAccessToken($_REQUEST['oauth_verifier']);
$account = $twitter->get('account/verify_credentials');
header('Location: ' . BASE_URL . 'connect/add/twitter/' . base64_encode($token['user_id']) . '/' . base64_encode($token['screen_name']) . '/' . base64_encode($token['oauth_token']) . '/' . base64_encode($token['oauth_token_secret']) . '/' . base64_encode($account->profile_image_url_https));
exit;
}
示例13: callbackAction
public function callbackAction(Request $request)
{
/****Check language session*******/
$session = $request->getSession();
$this->langsession($session);
$lan = $session->get('language');
$request->setLocale($lan);
$username = $session->get('user');
$em = $this->getDoctrine()->getManager();
$appkey = $this->container->get('mytrip_admin.helper.twitter')->getOption('apikey');
$appsecretkey = $this->container->get('mytrip_admin.helper.twitter')->getOption('apisecretkey');
$twitteroauth = new \TwitterOAuth($appkey, $appsecretkey, $session->get('oauth_token'), $session->get('oauth_token_secret'));
//\TwitterOAuth::setAuth($appkey, $appsecretkey,$session->get('oauth_token'), $session->get('oauth_token_secret'));
$access_token = $twitteroauth->getAccessToken($_REQUEST['oauth_verifier']);
$content = $twitteroauth->get('account/verify_credentials');
if (!empty($content)) {
if (!empty($username)) {
$uid = $username['userId'];
$check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='" . $uid . "' AND p.socialLink='Twitter' AND p.id='" . $content->id . "'")->getArrayResult();
if (empty($check_social_link)) {
$social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink();
$social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid));
$social_links->setSocialLink('Twitter');
$social_links->setId($content->id);
$social_links->setImage($content->profile_image_url);
$social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s')));
$em->persist($social_links);
$em->flush();
}
return $this->redirect($this->generateUrl('mytrip_user_profile'));
} else {
$check_social_link = $em->createQuery("SELECT p,IDENTITY(p.user) AS user FROM MytripAdminBundle:UserSocialLink p WHERE p.socialLink='Twitter' AND p.id='" . $content->id . "'")->getArrayResult();
if (!empty($check_social_link)) {
$user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $check_social_link[0]['user'] . "' AND p.status NOT IN ('Trash')")->getArrayResult();
if (!empty($user)) {
$session->set('user', $user[0]);
$session->set('UserLogin', "True");
return $this->redirect($this->generateUrl('mytrip_user_profile'));
} else {
$session->set('twittercontent', $content);
$this->get('session')->getFlashBag()->add('twit', '1');
return $this->redirect($this->generateUrl('mytrip_user_homepage'));
}
} else {
$session->set('twittercontent', $content);
$this->get('session')->getFlashBag()->add('twit', '1');
return $this->redirect($this->generateUrl('mytrip_user_homepage'));
}
}
} else {
$this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Sorry, Please try again'));
if (empty($username)) {
return $this->redirect($this->generateUrl('mytrip_user_homepage'));
} else {
return $this->redirect($this->generateUrl('mytrip_user_profile'));
}
}
}
示例14: processAuth
/**
* This method is used to process the second part of authentication workflow, after redirect
*
* @return array Array with status and user details
*/
public function processAuth()
{
$ngConnectINI = eZINI::instance('ngconnect.ini');
$http = eZHTTPTool::instance();
$consumerKey = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerKey'));
$consumerSecret = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerSecret'));
if (empty($consumerKey) || empty($consumerSecret)) {
return array('status' => 'error', 'message' => 'Consumer key or consumer secret undefined.');
}
$oAuthToken = trim($http->getVariable('oauth_token', ''));
$oAuthVerifier = trim($http->getVariable('oauth_verifier', ''));
$state = trim($http->getVariable('state', ''));
if (empty($oAuthToken) || empty($oAuthVerifier) || empty($state)) {
return array('status' => 'error', 'message' => 'oauth_token, oauth_verifier or state GET parameters undefined.');
}
if (!$http->hasSessionVariable('NGConnectOAuthState') || $state != $http->sessionVariable('NGConnectOAuthState')) {
$http->removeSessionVariable('NGConnectOAuthState');
return array('status' => 'error', 'message' => 'State parameter does not match stored value.');
} else {
$http->removeSessionVariable('NGConnectOAuthState');
}
if (!$http->hasSessionVariable('NGConnectOAuthToken') || !$http->hasSessionVariable('NGConnectOAuthTokenSecret') || $oAuthToken != $http->sessionVariable('NGConnectOAuthToken')) {
$http->removeSessionVariable('NGConnectOAuthToken');
$http->removeSessionVariable('NGConnectOAuthTokenSecret');
return array('status' => 'error', 'message' => 'Token does not match stored value.');
} else {
$oAuthTokenSecret = $http->sessionVariable('NGConnectOAuthTokenSecret');
$http->removeSessionVariable('NGConnectOAuthToken');
$http->removeSessionVariable('NGConnectOAuthTokenSecret');
}
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthTokenSecret);
$connection->host = self::TWITTER_API_URI;
$accessToken = $connection->getAccessToken($oAuthVerifier);
if (!(isset($accessToken['oauth_token']) && isset($accessToken['oauth_token_secret']))) {
return array('status' => 'error', 'message' => 'Error while retrieving access token.');
}
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken['oauth_token'], $accessToken['oauth_token_secret']);
$connection->host = self::TWITTER_API_URI;
$user = $connection->get(self::TWITTER_USER_API_URI);
if (!isset($user->id) || empty($user->id)) {
return array('status' => 'error', 'message' => 'Invalid Twitter user.');
}
if (isset($user->profile_image_url) && !empty($user->profile_image_url)) {
$pictureUri = $user->profile_image_url;
$imageSize = trim($ngConnectINI->variable('LoginMethod_twitter', 'ImageSize'));
if ($imageSize == 'original') {
//Hm... it seems there's no way to get the full size image through API
//Even https://api.twitter.com/1/users/profile_image/username never returns full version
//Replacing is not safe, but at least we're replacing last occurrence
$pictureUri = substr_replace($user->profile_image_url, '', strrpos($user->profile_image_url, '_normal'), 7);
}
} else {
$pictureUri = '';
}
$result = array('status' => 'success', 'login_method' => 'twitter', 'id' => $user->id, 'first_name' => isset($user->name) ? $user->name : '', 'last_name' => '', 'email' => '', 'picture' => $pictureUri);
return $result;
}
示例15: action_twittercallback
public function action_twittercallback()
{
if (arr::get($_GET, 'denied', false)) {
notes::error('Seems like you didn\'t want to log in with Twitter anyway. Feel free to try again if it was a mistake!');
site::redirect();
}
$token = arr::get($_GET, 'oauth_token', false);
$verifier = arr::get($_GET, 'oauth_verifier', false);
if (!$token || !$verifier) {
notes::error('Something went wrong in the process, and we didn\'t get the expected data back from Twitter. Please try again');
site::redirect();
}
$connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret'), Session::instance()->get_once('twitter_oauth_token'), Session::instance()->get_once('twitter_oauth_token_secret'));
$token = $connection->getAccessToken($verifier);
$oauth_token = arr::get($token, 'oauth_token', '');
$oauth_token_secret = arr::get($token, 'oauth_token_secret', '');
$user_id = arr::get($token, 'user_id', '');
$screen_name = arr::get($token, 'screen_name', '');
$oauth = ORM::factory('Oauth')->where('type', '=', 'twitter')->where('token', '=', $oauth_token)->find();
if ($oauth->loaded()) {
try {
$user = $oauth->user;
user::force_login($user);
} catch (exception $e) {
if ($user->loaded()) {
if (user::logged()) {
// Random error, but user got logged in. We don't care, YOLO!
} else {
notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
Kohana::$log->add(Log::ERROR, '1. Couldnt log user in: ' . $e->getMessage());
}
}
}
site::redirect('write');
} else {
try {
$user = ORM::factory('User');
$user->username = $screen_name;
$user->validation_required(false)->save();
$user->add_role('login');
$oauth = ORM::factory('Oauth');
$oauth->user_id = $user->id;
$oauth->type = 'twitter';
$oauth->token = $oauth_token;
$oauth->token_secret = $oauth_token_secret;
$oauth->service_id = $user_id;
$oauth->screen_name = $screen_name;
$oauth->save();
user::force_login($user);
} catch (exception $e) {
Kohana::$log->add(Log::ERROR, '2. Couldnt create user: ' . $e->getMessage());
notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
}
site::redirect('/write');
}
}