web/tweet.php
changeset 1427 8b3d57a519eb
parent 229 74c9ddc3640b
child 1557 7c67caaafdeb
--- a/web/tweet.php	Fri Jun 15 08:40:12 2018 +0000
+++ b/web/tweet.php	Mon Jun 18 23:15:34 2018 +0200
@@ -7,6 +7,7 @@
 $rep = $_REQUEST['rep'];
 include_once dirname(__FILE__).'/'.$rep.'/config.php';
 include_once 'common.php';
+use Abraham\TwitterOAuth\TwitterOAuth;
 
 /**
  * Check for a POSTed status message to send to Twitter
@@ -18,21 +19,28 @@
      * a preconfigured instance of Zend_Http_Client which automatically
      * signs and encodes all our requests without additional work
      */
+    // $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
+    // $client = $token->getHttpClient($configuration);
+    // $client->setUri('http://twitter.com/statuses/update.json');
+    // $client->setMethod(Zend_Http_Client::POST);
+    // $client->setParameterPost('status', $_POST['status']);
+    // $response = $client->request();
     $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
-    $client = $token->getHttpClient($configuration);
-    $client->setUri('http://twitter.com/statuses/update.json');
-    $client->setMethod(Zend_Http_Client::POST);
-    $client->setParameterPost('status', $_POST['status']);
-    $response = $client->request();
+    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
+
+    $data = $connection->post("statuses/update", ["status" => $_POST['status']]);
+
 
     /**
      * Check if the json response refers to our tweet details (assume it
      * means it was successfully posted). API gurus can correct me.
      */
-    $data = json_decode($response->getBody());
-    $result = $response->getBody();
+    // $data = json_decode($response->getBody());
+    // $result = $response->getBody();
     if (isset($data->text)) {
         $result = 'true';
+    } else {
+        $result = json_encode($data);
     }
     /**
      * Tweet sent (hopefully), redirect back home...