summaryrefslogtreecommitdiff
path: root/lib/twitteroauthclient.php
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-08-03 22:46:01 +0000
committerZach Copley <zach@controlyourself.ca>2009-08-03 22:46:01 +0000
commit981fa1b33a8073bd0d53d8bee7dfccd171685e61 (patch)
tree2c72d5d6c21b51c930eae789414d075a1b7f02df /lib/twitteroauthclient.php
parent6f4b2f0ac2f235332c850b050d9e4563fc71f89d (diff)
Make the TwitterQueuehandler post to Twitter using OAuth
Diffstat (limited to 'lib/twitteroauthclient.php')
-rw-r--r--lib/twitteroauthclient.php39
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/twitteroauthclient.php b/lib/twitteroauthclient.php
index 616fbc213..63ffe1c7c 100644
--- a/lib/twitteroauthclient.php
+++ b/lib/twitteroauthclient.php
@@ -2,6 +2,8 @@
require_once('OAuth.php');
+class OAuthClientCurlException extends Exception { }
+
class TwitterOAuthClient
{
public static $requestTokenURL = 'https://twitter.com/oauth/request_token';
@@ -54,6 +56,16 @@ class TwitterOAuthClient
return $twitter_user;
}
+ function statuses_update($status, $in_reply_to_status_id = null)
+ {
+ $url = 'https://twitter.com/statuses/update.json';
+ $params = array('status' => $status,
+ 'in_reply_to_status_id' => $in_reply_to_status_id);
+ $response = $this->oAuthPost($url, $params);
+ $status = json_decode($response);
+ return $status;
+ }
+
function oAuthGet($url)
{
$request = OAuthRequest::from_consumer_and_token($this->consumer,
@@ -91,19 +103,26 @@ class TwitterOAuthClient
// Twitter is strict about accepting invalid "Expect" headers
CURLOPT_HTTPHEADER => array('Expect:')
- );
+ );
- if (isset($params)) {
- $options[CURLOPT_POST] = true;
- $options[CURLOPT_POSTFIELDS] = $params;
- }
+ if (isset($params)) {
+ $options[CURLOPT_POST] = true;
+ $options[CURLOPT_POSTFIELDS] = $params;
+ }
+
+ $ch = curl_init($url);
+ curl_setopt_array($ch, $options);
+ $response = curl_exec($ch);
+
+ if ($response === false) {
+ $msg = curl_error($ch);
+ $code = curl_errno($ch);
+ throw new OAuthClientCurlException($msg, $code);
+ }
- $ch = curl_init($url);
- curl_setopt_array($ch, $options);
- $response = curl_exec($ch);
- curl_close($ch);
+ curl_close($ch);
- return $response;
+ return $response;
}
}