web/search_tweets.php
author Raphael Velt <raph.velt@gmail.com>
Wed, 10 Apr 2013 18:13:54 +0200
changeset 879 f0d599e75860
child 919 e126d3e1e186
permissions -rw-r--r--
Added tweet search proxy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
879
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     1
<?php
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     2
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     3
header("Content-type: application/json");
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     4
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     5
/**
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     6
 * include some common code (like we did in the 90s)
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     7
 * People still do this? ;)
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     8
 */
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     9
include_once 'common.php';
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    10
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    11
/**
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    12
 * Check for a POSTed status message to send to Twitter
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    13
 */
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    14
if (!empty($_GET)
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    15
&& isset($_SESSION['TWITTER_ACCESS_TOKEN'])) {
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    16
    /**
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    17
     * Easiest way to use OAuth now that we have an Access Token is to use
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    18
     * a preconfigured instance of Zend_Http_Client which automatically
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    19
     * signs and encodes all our requests without additional work
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    20
     */
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    21
    $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    22
    $client = $token->getHttpClient($configuration);
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    23
    $client->setUri('https://api.twitter.com/1.1/search/tweets.json');
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    24
    $client->setMethod(Zend_Http_Client::GET);
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    25
    $client->setParameterGet($_GET);
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    26
    $response = $client->request();
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    27
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    28
    echo $response->getBody();
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    29
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    30
} else {
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    31
    /**
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    32
     * Mistaken request? Some malfeasant trying something?
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    33
     */
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    34
    exit('Invalid tweet request. Oops. Sorry.');
f0d599e75860 Added tweet search proxy
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    35
}