summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-08-28 07:02:27 +0000
committerZach Copley <zach@controlyourself.ca>2009-08-28 07:02:27 +0000
commit36c104fb34d7128a0372dd3f77504c0b2f76ba80 (patch)
tree95c03e5a3b0e3b096e3d1febf4ce21a562507bfb
parent36b6ef8d05bf6e4290894f9677cc9618a9bfd486 (diff)
Make SyncTwitterFriends and TwitterStatusFetcher daemons use both HTTP Basic Auth as well as OAuth
-rw-r--r--lib/oauthclient.php2
-rw-r--r--lib/twitterbasicauthclient.php6
-rw-r--r--lib/twitteroauthclient.php2
-rwxr-xr-xscripts/synctwitterfriends.php17
-rwxr-xr-xscripts/twitterqueuehandler.php2
-rwxr-xr-xscripts/twitterstatusfetcher.php21
6 files changed, 35 insertions, 15 deletions
diff --git a/lib/oauthclient.php b/lib/oauthclient.php
index cc10cea8f..f1827726e 100644
--- a/lib/oauthclient.php
+++ b/lib/oauthclient.php
@@ -22,7 +22,7 @@
* @category Action
* @package StatusNet
* @author Zach Copley <zach@status.net>
- * @copyright 2008 StatusNet, Inc.
+ * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
diff --git a/lib/twitterbasicauthclient.php b/lib/twitterbasicauthclient.php
index 82359d93d..66bb01e53 100644
--- a/lib/twitterbasicauthclient.php
+++ b/lib/twitterbasicauthclient.php
@@ -88,7 +88,7 @@ class TwitterBasicAuthClient
$params = array('status' => $status,
'source' => common_config('integration', 'source'),
'in_reply_to_status_id' => $in_reply_to_status_id);
- $response = $this->httpRequest($url, $params, true);
+ $response = $this->httpRequest($url, $params);
$status = json_decode($response);
return $status;
}
@@ -117,7 +117,7 @@ class TwitterBasicAuthClient
$url .= "?$qry";
}
- $response = $this->httpRequest($url, null, true);
+ $response = $this->httpRequest($url);
$statuses = json_decode($response);
return $statuses;
}
@@ -190,7 +190,7 @@ class TwitterBasicAuthClient
*
* @return mixed the request
*/
- function httpRequest($url, $params = null, $auth = false)
+ function httpRequest($url, $params = null, $auth = true)
{
$options = array(
CURLOPT_RETURNTRANSFER => true,
diff --git a/lib/twitteroauthclient.php b/lib/twitteroauthclient.php
index 9821a491e..e37fa05f0 100644
--- a/lib/twitteroauthclient.php
+++ b/lib/twitteroauthclient.php
@@ -22,7 +22,7 @@
* @category Integration
* @package StatusNet
* @author Zach Copley <zach@status.net>
- * @copyright 2008 StatusNet, Inc.
+ * @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php
index 545cb23b3..2cb7525ea 100755
--- a/scripts/synctwitterfriends.php
+++ b/scripts/synctwitterfriends.php
@@ -19,6 +19,8 @@
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+define('LACONICA', true); // compatibility
$shortoptions = 'di::';
$longoptions = array('id::', 'debug');
@@ -142,13 +144,20 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
{
$friends = array();
- $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = null;
- $client = new TwitterOAuthClient($token->key, $token->secret);
+ if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
+ $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = new TwitterOAuthClient($token->key, $token->secret);
+ common_debug($this->name() . '- Grabbing friends IDs with OAuth.');
+ } else {
+ $client = new TwitterBasicAuthClient($flink);
+ common_debug($this->name() . '- Grabbing friends IDs with basic auth.');
+ }
try {
$friends_ids = $client->friendsIds();
- } catch (OAuthCurlException $e) {
+ } catch (Exception $e) {
common_log(LOG_WARNING, $this->name() .
' - cURL error getting friend ids ' .
$e->getCode() . ' - ' . $e->getMessage());
@@ -177,7 +186,7 @@ class SyncTwitterFriendsDaemon extends ParallelizingDaemon
try {
$more_friends = $client->statusesFriends(null, null, null, $i);
- } catch (OAuthCurlException $e) {
+ } catch (Exception $e) {
common_log(LOG_WARNING, $this->name() .
' - cURL error getting Twitter statuses/friends ' .
"page $i - " . $e->getCode() . ' - ' .
diff --git a/scripts/twitterqueuehandler.php b/scripts/twitterqueuehandler.php
index ce4d824d0..992141f9d 100755
--- a/scripts/twitterqueuehandler.php
+++ b/scripts/twitterqueuehandler.php
@@ -19,6 +19,8 @@
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+define('LACONICA', true); // compatibility
$shortoptions = 'i::';
$longoptions = array('id::');
diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php
index 68f7e9bf7..6dca6f75b 100755
--- a/scripts/twitterstatusfetcher.php
+++ b/scripts/twitterstatusfetcher.php
@@ -19,6 +19,8 @@
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+define('LACONICA', true); // compatibility
// Tune number of processes and how often to poll Twitter
// XXX: Should these things be in config.php?
@@ -148,9 +150,9 @@ class TwitterStatusFetcher extends ParallelizingDaemon
function getTimeline($flink)
{
- if (empty($flink)) {
+ if (empty($flink)) {
common_log(LOG_WARNING, $this->name() .
- " - Can't retrieve Foreign_link for foreign ID $fid");
+ " - Can't retrieve Foreign_link for foreign ID $fid");
return;
}
@@ -161,17 +163,24 @@ class TwitterStatusFetcher extends ParallelizingDaemon
// to start importing? How many statuses? Right now I'm going
// with the default last 20.
- $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = null;
- $client = new TwitterOAuthClient($token->key, $token->secret);
+ if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
+ $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = new TwitterOAuthClient($token->key, $token->secret);
+ common_debug($this->name() . ' - Grabbing friends timeline with OAuth.');
+ } else {
+ $client = new TwitterBasicAuthClient($flink);
+ common_debug($this->name() . ' - Grabbing friends timeline with basic auth.');
+ }
$timeline = null;
try {
$timeline = $client->statusesFriendsTimeline();
- } catch (OAuthClientCurlException $e) {
+ } catch (Exception $e) {
common_log(LOG_WARNING, $this->name() .
- ' - OAuth client unable to get friends timeline for user ' .
+ ' - Twitter client unable to get friends timeline for user ' .
$flink->user_id . ' - code: ' .
$e->getCode() . 'msg: ' . $e->getMessage());
}