summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-08-03 22:46:01 +0000
committerZach Copley <zach@controlyourself.ca>2009-08-03 22:46:01 +0000
commit981fa1b33a8073bd0d53d8bee7dfccd171685e61 (patch)
tree2c72d5d6c21b51c930eae789414d075a1b7f02df /actions
parent6f4b2f0ac2f235332c850b050d9e4563fc71f89d (diff)
Make the TwitterQueuehandler post to Twitter using OAuth
Diffstat (limited to 'actions')
-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();