Added tweet search proxy
authorRaphael Velt <raph.velt@gmail.com>
Wed, 10 Apr 2013 18:13:54 +0200
changeset 879 f0d599e75860
parent 878 bead0341e247
child 880 ac8b456b8874
Added tweet search proxy
web/search_tweets.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/search_tweets.php	Wed Apr 10 18:13:54 2013 +0200
@@ -0,0 +1,35 @@
+<?php
+
+header("Content-type: application/json");
+
+/**
+ * include some common code (like we did in the 90s)
+ * People still do this? ;)
+ */
+include_once 'common.php';
+
+/**
+ * Check for a POSTed status message to send to Twitter
+ */
+if (!empty($_GET)
+&& isset($_SESSION['TWITTER_ACCESS_TOKEN'])) {
+    /**
+     * Easiest way to use OAuth now that we have an Access Token is to use
+     * 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('https://api.twitter.com/1.1/search/tweets.json');
+    $client->setMethod(Zend_Http_Client::GET);
+    $client->setParameterGet($_GET);
+    $response = $client->request();
+
+    echo $response->getBody();
+
+} else {
+    /**
+     * Mistaken request? Some malfeasant trying something?
+     */
+    exit('Invalid tweet request. Oops. Sorry.');
+}