Skip to content

Instantly share code, notes, and snippets.

@pendexgabo
Created May 8, 2009 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pendexgabo/108983 to your computer and use it in GitHub Desktop.
Save pendexgabo/108983 to your computer and use it in GitHub Desktop.
Index: twitter.lib.php
===================================================================
--- twitter.lib.php (revision 2025)
+++ twitter.lib.php (working copy)
@@ -37,6 +37,15 @@
* @package twitterlibphp
*/
abstract class TwitterBase {
+
+
+ /**
+ * this is case the method should be called by post
+ * @access protected
+ * @var array
+ * @author Gabriel Sosa @pendexgabo
+ */
+ protected $_options;
/**
* the last HTTP status code returned
@@ -115,7 +124,7 @@
if ($reply_to) {
$args['in_reply_to_status_id'] = $reply_to;
}
- $api_call = $this->buildRequest('statuses/update', $format, $args);
+ $api_call = $this->buildRequest('statuses/update', $format, $args, true);
return $this->APICall($api_call, true, true);
}
@@ -456,7 +465,7 @@
* @param $options array API method options
* @return string
*/
- private function buildRequest($method, $fmt, $options = array()) {
+ private function buildRequest($method, $fmt, $options = array(), $post = false) {
$request = sprintf('http://twitter.com/%s.%s', $method, $fmt);
/* Add application source to the options */
if ($this->application_source) {
@@ -468,7 +477,17 @@
foreach($options as $option => $value) {
array_push($keyvals, sprintf('%s=%s', $option, $value));
}
- $request .= '?' . implode($keyvals, '&');
+ $opt_string = implode($keyvals, '&');
+
+ if ($post == false) {
+ $request .= '?' . $opt_string;
+ }
+
+ /*
+ * we save this in case the request should be done by post
+ */
+ $this->_options = $opt_string;
+
}
return $request;
}
@@ -522,7 +541,6 @@
* @return string
*/
protected function APICall($api_url, $require_credentials = false, $http_post = false) {
-
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $api_url);
if ($require_credentials) {
@@ -530,10 +548,12 @@
}
if ($http_post) {
curl_setopt($curl_handle, CURLOPT_POST, true);
+ curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->_options);
}
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
$twitter_data = curl_exec($curl_handle);
+ //print_r(curl_getinfo($curl_handle));
$this->http_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
$this->last_api_call = $api_url;
curl_close($curl_handle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment