summaryrefslogtreecommitdiff
path: root/actions/twitterauthorization.php
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-08-03 22:46:01 +0000
committerEvan Prodromou <evan@controlyourself.ca>2009-08-24 11:52:28 -0400
commit500f0c70725ebd4d0765ec547c7739d8f8268c39 (patch)
tree917aaf1a403fe8fdac447e56219a39e8894ede61 /actions/twitterauthorization.php
parente9edaab3588b18677c2b37a3115f447307e64689 (diff)
Make the TwitterQueuehandler post to Twitter using OAuth
Diffstat (limited to 'actions/twitterauthorization.php')
-rw-r--r--actions/twitterauthorization.php48
1 files changed, 33 insertions, 15 deletions
diff --git a/actions/twitterauthorization.php b/actions/twitterauthorization.php
index f19cd7f65..519427dac 100644
--- a/actions/twitterauthorization.php
+++ b/actions/twitterauthorization.php
@@ -67,39 +67,57 @@ class TwitterauthorizationAction extends Action
if (empty($this->oauth_token)) {
- // Get a new request token and authorize it
+ try {
- $client = new TwitterOAuthClient();
- $req_tok = $client->getRequestToken();
+ // Get a new request token and authorize it
- // Sock the request token away in the session temporarily
+ $client = new TwitterOAuthClient();
+ $req_tok = $client->getRequestToken();
- $_SESSION['twitter_request_token'] = $req_tok->key;
- $_SESSION['twitter_request_token_secret'] = $req_tok->key;
+ // Sock the request token away in the session temporarily
+
+ $_SESSION['twitter_request_token'] = $req_tok->key;
+ $_SESSION['twitter_request_token_secret'] = $req_tok->key;
+
+ $auth_link = $client->getAuthorizeLink($req_tok);
+
+ } catch (TwitterOAuthClientException $e) {
+ $msg = sprintf('OAuth client cURL error - code: %1s, msg: %2s',
+ $e->getCode(), $e->getMessage());
+ $this->serverError(_('Couldn\'t link your Twitter account.'));
+ }
- $auth_link = $client->getAuthorizeLink($req_tok);
common_redirect($auth_link);
} else {
- // Check to make sure Twitter sent us the same request token we sent
+ // Check to make sure Twitter returned the same request
+ // token we sent them
if ($_SESSION['twitter_request_token'] != $this->oauth_token) {
$this->serverError(_('Couldn\'t link your Twitter account.'));
}
- $client = new TwitterOAuthClient($_SESSION['twitter_request_token'],
- $_SESSION['twitter_request_token_secret']);
+ try {
- // Exchange the request token for an access token
+ $client = new TwitterOAuthClient($_SESSION['twitter_request_token'],
+ $_SESSION['twitter_request_token_secret']);
- $atok = $client->getAccessToken();
+ // Exchange the request token for an access token
- // Save the access token and Twitter user info
+ $atok = $client->getAccessToken();
- $client = new TwitterOAuthClient($atok->key, $atok->secret);
+ // Save the access token and Twitter user info
- $twitter_user = $client->verify_credentials();
+ $client = new TwitterOAuthClient($atok->key, $atok->secret);
+
+ $twitter_user = $client->verify_credentials();
+
+ } catch (OAuthClientException $e) {
+ $msg = sprintf('OAuth client cURL error - code: %1s, msg: %2s',
+ $e->getCode(), $e->getMessage());
+ $this->serverError(_('Couldn\'t link your Twitter account.'));
+ }
$user = common_current_user();