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.
This commit is contained in:
Zach Copley 2009-08-10 07:00:59 +00:00
parent fa8433308f
commit 27548c6903
6 changed files with 31 additions and 8 deletions

View File

@ -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

View File

@ -121,8 +121,6 @@ class OAuthClient
$authorize_url .= '&oauth_callback=' . urlencode($oauth_callback);
}
common_debug("$authorize_url");
return $authorize_url;
}

View File

@ -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;

View File

@ -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
*

View File

@ -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();

View File

@ -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;