From 252ebbe48eecb323b46b48bdf4906d2b01d168cc Mon Sep 17 00:00:00 2001 From: Andy Graulund Date: Tue, 2 Jul 2013 21:17:03 +0200 Subject: [PATCH] Fixed bug in internal Twitter API query function that occured after the switch to OAuth --- inc/class.twitterapi.php | 4 ++-- maintenance/loadtweets.php | 44 +++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/inc/class.twitterapi.php b/inc/class.twitterapi.php index 12d5771d..e152c3e8 100644 --- a/inc/class.twitterapi.php +++ b/inc/class.twitterapi.php @@ -27,8 +27,8 @@ public function __construct() { $this->connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $config['twitter_token'], $config['twitter_token_secr']); } - public function query($path){ - return $this->connection->get($path); + public function query($path, $parameters = array()){ + return $this->connection->get($path, $parameters); } //TODO: BUILD IN SUPPORT FOR "RATE LIMIT EXCEEDED" diff --git a/maintenance/loadtweets.php b/maintenance/loadtweets.php index 82d2246b..c0ba4a5a 100644 --- a/maintenance/loadtweets.php +++ b/maintenance/loadtweets.php @@ -46,7 +46,8 @@ function totalTweets($p){ global $twitterApi; $p = trim($p); if(!$twitterApi->validateUserParam($p)){ return false; } - $data = $twitterApi->query("users/show.json?" . $p); + $p = explode('=', $p); + $data = $twitterApi->query('users/show', array($p[0] => $p[1])); if(is_array($data) && $data[0] === false){ dieout(l(bad("Error: " . $data[1] . "/" . $data[2]))); } return $data->statuses_count; } @@ -59,6 +60,8 @@ function importTweets($p){ $tweets = array(); $sinceID = 0; $maxID = 0; + + list($userparam, $uservalue) = explode('=', $p); echo l("Importing:\n"); @@ -93,14 +96,24 @@ function importTweets($p){ // Retrieve tweets do { - // Determine path to Twitter timeline resource - $path = "statuses/user_timeline.json?" . $p . // <-- user argument - "&include_rts=true&include_entities=true&count=" . $maxCount . - ($sinceID ? "&since_id=" . $sinceID : "") . ($maxID ? "&max_id=" . $maxID : ""); // Announce - echo l("Retrieving page #" . $page . ": " . ls($path) . "\n"); + echo l("Retrieving page #" . $page . ":\n"); // Get data - $data = $twitterApi->query($path); + $params = array( + $userparam => $uservalue, + 'include_rts' => true, + 'include_entities' => true, + 'count' => $maxCount + ); + + if($sinceID){ + $params['since_id'] = $sinceID; + } + if($maxID){ + $params['max_id'] = $maxID; + } + + $data = $twitterApi->query('statuses/user_timeline', $params); // Drop out on connection error if(is_array($data) && $data[0] === false){ dieout(l(bad("Error: " . $data[1] . "/" . $data[2]))); } @@ -160,11 +173,22 @@ function importTweets($p){ // Resetting these $favs = array(); $maxID = 0; $sinceID = 0; $page = 1; do { - $path = "favorites/list.json?" . $p . "&count=" . $maxCount . ($maxID ? "&max_id=" . $maxID : ""); - echo l("Retrieving page #" . $page . ": " . ls($path) . "\n"); - $data = $twitterApi->query($path); + echo l("Retrieving page #" . $page . ":\n"); + + $params = array( + $userparam => $uservalue, + 'count' => $maxCount + ); + + if($maxID){ + $params['max_id'] = $maxID; + } + + $data = $twitterApi->query('favorites/list', $params); + if(is_array($data) && $data[0] === false){ dieout(l(bad("Error: " . $data[1] . "/" . $data[2]))); } echo l("" . ($data ? count($data) : 0) . " total favorite tweets on this page\n"); + if(!empty($data)){ echo l("