forked from GNUsocial/gnu-social
Make TwitterStatusFetcher daemon work with OAuth
This commit is contained in:
parent
ee006dbb0e
commit
fd9d653eb3
@ -39,4 +39,23 @@ class TwitterOAuthClient extends OAuthClient
|
|||||||
return $status;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ class TwitterStatusFetcher extends Daemon
|
|||||||
{
|
{
|
||||||
$flink = new Foreign_link();
|
$flink = new Foreign_link();
|
||||||
|
|
||||||
$flink->service = 1; // Twitter
|
$flink->service = TWITTER_SERVICE;
|
||||||
|
|
||||||
$flink->orderBy('last_noticesync');
|
$flink->orderBy('last_noticesync');
|
||||||
|
|
||||||
@ -241,35 +241,33 @@ class TwitterStatusFetcher extends Daemon
|
|||||||
|
|
||||||
function getTimeline($flink)
|
function getTimeline($flink)
|
||||||
{
|
{
|
||||||
if (empty($flink)) {
|
if (empty($flink)) {
|
||||||
common_log(LOG_WARNING,
|
common_log(LOG_WARNING,
|
||||||
"Can't retrieve Foreign_link for foreign ID $fid");
|
"Can't retrieve Foreign_link for foreign ID $fid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fuser = $flink->getForeignUser();
|
|
||||||
|
|
||||||
if (empty($fuser)) {
|
|
||||||
common_log(LOG_WARNING, "Unmatched user for ID " .
|
|
||||||
$flink->user_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defined('SCRIPT_DEBUG')) {
|
if (defined('SCRIPT_DEBUG')) {
|
||||||
common_debug('Trying to get timeline for Twitter user ' .
|
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
|
// XXX: Biggest remaining issue - How do we know at which status
|
||||||
// to start importing? How many statuses? Right now I'm going
|
// to start importing? How many statuses? Right now I'm going
|
||||||
// with the default last 20.
|
// 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,
|
$timeline = null;
|
||||||
$flink->credentials);
|
|
||||||
|
|
||||||
$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)) {
|
if (empty($timeline)) {
|
||||||
common_log(LOG_WARNING, "Empty timeline.");
|
common_log(LOG_WARNING, "Empty timeline.");
|
||||||
@ -303,7 +301,7 @@ class TwitterStatusFetcher extends Daemon
|
|||||||
$id = $this->ensureProfile($status->user);
|
$id = $this->ensureProfile($status->user);
|
||||||
$profile = Profile::staticGet($id);
|
$profile = Profile::staticGet($id);
|
||||||
|
|
||||||
if (!$profile) {
|
if (empty($profile)) {
|
||||||
common_log(LOG_ERR,
|
common_log(LOG_ERR,
|
||||||
'Problem saving notice. No associated Profile.');
|
'Problem saving notice. No associated Profile.');
|
||||||
return null;
|
return null;
|
||||||
@ -318,7 +316,7 @@ class TwitterStatusFetcher extends Daemon
|
|||||||
|
|
||||||
// check to see if we've already imported the status
|
// check to see if we've already imported the status
|
||||||
|
|
||||||
if (!$notice) {
|
if (empty($notice)) {
|
||||||
|
|
||||||
$notice = new Notice();
|
$notice = new Notice();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user