5 * People still do this? ;) |
5 * People still do this? ;) |
6 */ |
6 */ |
7 $rep = $_REQUEST['rep']; |
7 $rep = $_REQUEST['rep']; |
8 include_once dirname(__FILE__).'/'.$rep.'/config.php'; |
8 include_once dirname(__FILE__).'/'.$rep.'/config.php'; |
9 include_once 'common.php'; |
9 include_once 'common.php'; |
|
10 use Abraham\TwitterOAuth\TwitterOAuth; |
10 |
11 |
11 /** |
12 /** |
12 * Check for a POSTed status message to send to Twitter |
13 * Check for a POSTed status message to send to Twitter |
13 */ |
14 */ |
14 if (!empty($_POST) && isset($_POST['status']) |
15 if (!empty($_POST) && isset($_POST['status']) |
16 /** |
17 /** |
17 * Easiest way to use OAuth now that we have an Access Token is to use |
18 * 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 * a preconfigured instance of Zend_Http_Client which automatically |
19 * signs and encodes all our requests without additional work |
20 * signs and encodes all our requests without additional work |
20 */ |
21 */ |
|
22 // $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); |
|
23 // $client = $token->getHttpClient($configuration); |
|
24 // $client->setUri('http://twitter.com/statuses/update.json'); |
|
25 // $client->setMethod(Zend_Http_Client::POST); |
|
26 // $client->setParameterPost('status', $_POST['status']); |
|
27 // $response = $client->request(); |
21 $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); |
28 $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']); |
22 $client = $token->getHttpClient($configuration); |
29 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']); |
23 $client->setUri('http://twitter.com/statuses/update.json'); |
30 |
24 $client->setMethod(Zend_Http_Client::POST); |
31 $data = $connection->post("statuses/update", ["status" => $_POST['status']]); |
25 $client->setParameterPost('status', $_POST['status']); |
32 |
26 $response = $client->request(); |
|
27 |
33 |
28 /** |
34 /** |
29 * Check if the json response refers to our tweet details (assume it |
35 * Check if the json response refers to our tweet details (assume it |
30 * means it was successfully posted). API gurus can correct me. |
36 * means it was successfully posted). API gurus can correct me. |
31 */ |
37 */ |
32 $data = json_decode($response->getBody()); |
38 // $data = json_decode($response->getBody()); |
33 $result = $response->getBody(); |
39 // $result = $response->getBody(); |
34 if (isset($data->text)) { |
40 if (isset($data->text)) { |
35 $result = 'true'; |
41 $result = 'true'; |
|
42 } else { |
|
43 $result = json_encode($data); |
36 } |
44 } |
37 /** |
45 /** |
38 * Tweet sent (hopefully), redirect back home... |
46 * Tweet sent (hopefully), redirect back home... |
39 */ |
47 */ |
40 header('Location: ' . URL_ROOT . '$rep/client.php?result=' . $result); |
48 header('Location: ' . URL_ROOT . '$rep/client.php?result=' . $result); |