/** * Called when Twitter returns an authorized request token. Exchanges * it for an access token and stores it. * * @return nothing */ function saveAccessToken() { // Check to make sure Twitter returned the same request // token we sent them if ($_SESSION['twitter_request_token'] != $this->oauth_token) { // TRANS: Server error displayed when linking to a Twitter account fails because of an incorrect oauth_token. throw new ServerException(_m('Could not link your Twitter account: oauth_token mismatch.')); } $twitter_user = null; try { $client = new TwitterOAuthClient($_SESSION['twitter_request_token'], $_SESSION['twitter_request_token_secret']); // Exchange the request token for an access token $atok = $client->getTwitterAccessToken($this->verifier); // Test the access token and get the user's Twitter info $client = new TwitterOAuthClient($atok->key, $atok->secret); $twitter_user = $client->verifyCredentials(); } catch (OAuthClientException $e) { $msg = sprintf('OAuth client error - code: %1$s, msg: %2$s', $e->getCode(), $e->getMessage()); common_log(LOG_INFO, 'Twitter bridge - ' . $msg); // TRANS: Server error displayed when linking to a Twitter account fails. throw new ServerException(_m('Could not link your Twitter account.')); } if ($this->scoped instanceof Profile) { // Save the access token and Twitter user info $this->saveForeignLink($this->scoped->getID(), $twitter_user->id, $atok); save_twitter_user($twitter_user->id, $twitter_user->screen_name); } else { $this->twuid = $twitter_user->id; $this->tw_fields = array("screen_name" => $twitter_user->screen_name, "fullname" => $twitter_user->name); $this->access_token = $atok; return $this->tryLogin(); } // Clean up the the mess we made in the session unset($_SESSION['twitter_request_token']); unset($_SESSION['twitter_request_token_secret']); if (common_logged_in()) { common_redirect(common_local_url('twittersettings')); } }