| author | ymh <ymh.work@gmail.com> |
| Sat, 22 Sep 2018 14:48:48 +0200 | |
| changeset 1465 | 201a829de81b |
| parent 1427 | 8b3d57a519eb |
| child 1474 | 53f0f4ed20c8 |
| permissions | -rw-r--r-- |
| 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 |
include_once 'common.php'; |
|
|
1427
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
11 |
use Abraham\TwitterOAuth\TwitterOAuth; |
| 836 | 12 |
|
13 |
/** |
|
14 |
* Check for a POSTed status message to send to Twitter |
|
15 |
*/ |
|
16 |
if (!empty($_GET) |
|
17 |
&& isset($_SESSION['TWITTER_ACCESS_TOKEN'])) { |
|
18 |
/** |
|
19 |
* Easiest way to use OAuth now that we have an Access Token is to use |
|
20 |
* a preconfigured instance of Zend_Http_Client which automatically |
|
21 |
* signs and encodes all our requests without additional work |
|
22 |
*/ |
|
23 |
||
|
1427
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
24 |
// if (isset($_GET['endpoint'])) { |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
25 |
// $endpoint = $_GET['endpoint']; |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
26 |
// unset($_GET['endpoint']); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
27 |
// } else { |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
28 |
// $endpoint = "search/tweets"; |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
29 |
// } |
| 836 | 30 |
|
31 |
$token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); |
|
|
1427
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
32 |
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']); |
| 836 | 33 |
|
|
1427
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
34 |
$statuses = $connection->get("search/tweets", $_GET); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
35 |
// $client = $token->getHttpClient($configuration); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
36 |
// $client->setUri("https://api.twitter.com/1.1/$endpoint.json"); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
37 |
// $client->setMethod(Zend_Http_Client::GET); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
38 |
// $client->setParameterGet($_GET); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
39 |
// $response = $client->request(); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
40 |
|
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
41 |
// echo $response->getBody(); |
|
8b3d57a519eb
remove dependency to Zend 1. Use composer to reduce the number of dependencies
ymh <ymh.work@gmail.com>
parents:
919
diff
changeset
|
42 |
echo json_encode($statuses); |
| 836 | 43 |
|
44 |
} else { |
|
45 |
/** |
|
46 |
* Mistaken request? Some malfeasant trying something? |
|
47 |
*/ |
|
48 |
exit('Invalid tweet request. Oops. Sorry.'); |
|
49 |
} |
|
50 |
?> |