|
| 1 | +<?php |
| 2 | +require '../src/Curl.class.php'; |
| 3 | + |
| 4 | + |
| 5 | +define('API_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXX'); |
| 6 | +define('API_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); |
| 7 | +define('OAUTH_ACCESS_TOKEN', 'XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); |
| 8 | +define('OAUTH_TOKEN_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); |
| 9 | + |
| 10 | +$status = 'I love php curl class. https://github.com/php-curl-class/php-curl-class'; |
| 11 | + |
| 12 | +$oauth_data = array( |
| 13 | + 'oauth_consumer_key' => API_KEY, |
| 14 | + 'oauth_nonce' => md5(microtime() . mt_rand()), |
| 15 | + 'oauth_signature_method' => 'HMAC-SHA1', |
| 16 | + 'oauth_timestamp' => time(), |
| 17 | + 'oauth_token' => OAUTH_ACCESS_TOKEN, |
| 18 | + 'oauth_version' => '1.0', |
| 19 | + 'status' => $status, |
| 20 | +); |
| 21 | + |
| 22 | +$url = 'https://api.twitter.com/1.1/statuses/update.json'; |
| 23 | +$request = implode('&', array( |
| 24 | + 'POST', |
| 25 | + rawurlencode($url), |
| 26 | + rawurlencode(http_build_query($oauth_data, '', '&', PHP_QUERY_RFC3986)), |
| 27 | +)); |
| 28 | +$key = implode('&', array(API_SECRET, OAUTH_TOKEN_SECRET)); |
| 29 | +$oauth_data['oauth_signature'] = base64_encode(hash_hmac('sha1', $request, $key, true)); |
| 30 | +$data = http_build_query($oauth_data, '', '&'); |
| 31 | + |
| 32 | +$curl = new Curl(); |
| 33 | +$curl->post($url, $data); |
| 34 | + |
| 35 | +echo 'Posted "' . $curl->response->text . '" at ' . $curl->response->created_at . '.' . "\n"; |
0 commit comments