From 27548c690350bdf0376d846a5e8e86477359297d Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 10 Aug 2009 07:00:59 +0000 Subject: [PATCH] I forgot that we don't do database upgrades for point releases. So I've changed Twitter OAuth to store token and token secret in the same field in foreign_link (credentials). This should be changed in 0.9. --- actions/twitterauthorization.php | 8 +++++--- lib/oauthclient.php | 2 -- lib/twitter.php | 4 +++- lib/twitteroauthclient.php | 17 +++++++++++++++++ scripts/synctwitterfriends.php | 4 +++- scripts/twitterstatusfetcher.php | 4 +++- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/actions/twitterauthorization.php b/actions/twitterauthorization.php index c40f27164a..b04f353278 100644 --- a/actions/twitterauthorization.php +++ b/actions/twitterauthorization.php @@ -113,7 +113,7 @@ class TwitterauthorizationAction extends Action // Get a new request token and authorize it $client = new TwitterOAuthClient(); - $req_tok = + $req_tok = $client->getRequestToken(TwitterOAuthClient::$requestTokenURL); // Sock the request token away in the session temporarily @@ -198,8 +198,10 @@ class TwitterauthorizationAction extends Action $flink->user_id = $user->id; $flink->foreign_id = $twitter_user->id; $flink->service = TWITTER_SERVICE; - $flink->token = $access_token->key; - $flink->credentials = $access_token->secret; + + $creds = TwitterOAuthClient::packToken($access_token); + + $flink->credentials = $creds; $flink->created = common_sql_now(); // Defaults: noticesync on, everything else off diff --git a/lib/oauthclient.php b/lib/oauthclient.php index 878e470911..b66a24be44 100644 --- a/lib/oauthclient.php +++ b/lib/oauthclient.php @@ -121,8 +121,6 @@ class OAuthClient $authorize_url .= '&oauth_callback=' . urlencode($oauth_callback); } - common_debug("$authorize_url"); - return $authorize_url; } diff --git a/lib/twitter.php b/lib/twitter.php index 4e2f67c66c..280cdb0a33 100644 --- a/lib/twitter.php +++ b/lib/twitter.php @@ -160,7 +160,9 @@ function broadcast_twitter($notice) // XXX: Hack to get around PHP cURL's use of @ being a a meta character $statustxt = preg_replace('/^@/', ' @', $notice->content); - $client = new TwitterOAuthClient($flink->token, $flink->credentials); + $token = TwitterOAuthClient::unpackToken($flink->credentials); + + $client = new TwitterOAuthClient($token->key, $token->secret); $status = null; diff --git a/lib/twitteroauthclient.php b/lib/twitteroauthclient.php index c798ac8771..b7dc4a80c3 100644 --- a/lib/twitteroauthclient.php +++ b/lib/twitteroauthclient.php @@ -64,6 +64,23 @@ class TwitterOAuthClient extends OAuthClient $oauth_token, $oauth_token_secret); } + // XXX: the following two functions are to support the horrible hack + // of using the credentils field in Foreign_link to store both + // the access token and token secret. This hack should go away with + // 0.9, in which we can make DB changes and add a new column for the + // token itself. + + static function packToken($token) + { + return implode(chr(0), array($token->key, $token->secret)); + } + + static function unpackToken($str) + { + $vals = explode(chr(0), $str); + return new OAuthToken($vals[0], $vals[1]); + } + /** * Builds a link to Twitter's endpoint for authorizing a request token * diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php index 39b9ad6127..d13500e979 100755 --- a/scripts/synctwitterfriends.php +++ b/scripts/synctwitterfriends.php @@ -142,7 +142,9 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon { $friends = array(); - $client = new TwitterOAuthClient($flink->token, $flink->credentials); + $token = TwitterOAuthClient::unpackToken($flink->credentials); + + $client = new TwitterOAuthClient($token->key, $token->secret); try { $friends_ids = $client->friendsIds(); diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index e04a8993f3..f5289c5f4b 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -161,7 +161,9 @@ class TwitterStatusFetcher extends ParallelizingDaemon // to start importing? How many statuses? Right now I'm going // with the default last 20. - $client = new TwitterOAuthClient($flink->token, $flink->credentials); + $token = TwitterOAuthClient::unpackToken($flink->credentials); + + $client = new TwitterOAuthClient($token->key, $token->secret); $timeline = null;