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