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