]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make TwitterStatusFetcher daemon work with OAuth
authorZach Copley <zach@controlyourself.ca>
Tue, 4 Aug 2009 02:21:18 +0000 (02:21 +0000)
committerEvan Prodromou <evan@controlyourself.ca>
Mon, 24 Aug 2009 15:53:43 +0000 (11:53 -0400)
lib/twitteroauthclient.php
scripts/twitterstatusfetcher.php

index e1190f16759df4aa2e5da8e72aeb7b08dfa171c4..aabda8d6ad18f404bde5f947d1a595992520f979 100644 (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;
+    }
+
 }
index e1745cfc089614f41aa8a5766f179e72a924f836..d9f035fa61a9742010b94f3c457d374915a02460 100755 (executable)
@@ -191,7 +191,7 @@ class TwitterStatusFetcher extends Daemon
     {
         $flink = new Foreign_link();
 
-        $flink->service = 1; // Twitter
+        $flink->service = TWITTER_SERVICE;
 
         $flink->orderBy('last_noticesync');
 
@@ -241,35 +241,33 @@ class TwitterStatusFetcher extends Daemon
 
     function getTimeline($flink)
     {
-        if (empty($flink)) {
+         if (empty($flink)) {
             common_log(LOG_WARNING,
                 "Can't retrieve Foreign_link for foreign ID $fid");
             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();