Make TwitterStatusFetcher daemon work with OAuth

This commit is contained in:
Zach Copley 2009-08-04 02:21:18 +00:00
parent f94ee5597d
commit fe9fc15286
2 changed files with 34 additions and 17 deletions

View File

@ -39,4 +39,23 @@ class TwitterOAuthClient extends OAuthClient
return $status;
}
function statuses_friends_timeline($since_id = null, $max_id = null,
$cnt = null, $page = null) {
$url = 'http://twitter.com/statuses/friends_timeline.json';
$params = array('since_id' => $since_id,
'max_id' => $max_id,
'count' => $cnt,
'page' => $page);
$qry = http_build_query($params);
if (!empty($qry)) {
$url .= "?$qry";
}
$response = $this->oAuthGet($url);
$statuses = json_decode($response);
return $statuses;
}
}

View File

@ -191,7 +191,7 @@ class TwitterStatusFetcher extends Daemon
{
$flink = new Foreign_link();
$flink->service = 1; // Twitter
$flink->service = TWITTER_SERVICE;
$flink->orderBy('last_noticesync');
@ -247,29 +247,27 @@ class TwitterStatusFetcher extends Daemon
return;
}
$fuser = $flink->getForeignUser();
if (empty($fuser)) {
common_log(LOG_WARNING, "Unmatched user for ID " .
$flink->user_id);
return;
}
if (defined('SCRIPT_DEBUG')) {
common_debug('Trying to get timeline for Twitter user ' .
"$fuser->nickname ($flink->foreign_id).");
$flink->foreign_id);
}
// XXX: Biggest remaining issue - How do we know at which status
// to start importing? How many statuses? Right now I'm going
// with the default last 20.
$url = 'http://twitter.com/statuses/friends_timeline.json';
$client = new TwitterOAuthClient($flink->token, $flink->credentials);
$timeline_json = get_twitter_data($url, $fuser->nickname,
$flink->credentials);
$timeline = null;
$timeline = json_decode($timeline_json);
try {
$timeline = $client->statuses_friends_timeline();
} catch (OAuthClientCurlException $e) {
common_log(LOG_WARNING,
'OAuth client unable to get friends timeline for user ' .
$flink->user_id . ' - code: ' .
$e->getCode() . 'msg: ' . $e->getMessage());
}
if (empty($timeline)) {
common_log(LOG_WARNING, "Empty timeline.");
@ -303,7 +301,7 @@ class TwitterStatusFetcher extends Daemon
$id = $this->ensureProfile($status->user);
$profile = Profile::staticGet($id);
if (!$profile) {
if (empty($profile)) {
common_log(LOG_ERR,
'Problem saving notice. No associated Profile.');
return null;
@ -318,7 +316,7 @@ class TwitterStatusFetcher extends Daemon
// check to see if we've already imported the status
if (!$notice) {
if (empty($notice)) {
$notice = new Notice();