echo <<<EOM tmhOAuth PHP Signature Generator. This script generates an OAuth signature from adhoc values. No requests are made to the Twitter API. EOM; } welcome(); $consumer_key = tmhUtilities::read_input(PHP_EOL . 'Consumer Key' . PHP_EOL); $consumer_secret = tmhUtilities::read_input(PHP_EOL . 'Consumer Secret' . PHP_EOL); $user_token = tmhUtilities::read_input(PHP_EOL . 'User Token' . PHP_EOL . '(this can be left blank for checking request_token calls)'); $user_secret = tmhUtilities::read_input(PHP_EOL . 'User Secret' . PHP_EOL . '(this can be left blank for checking request_token calls)'); $timestamp = tmhUtilities::read_input(PHP_EOL . 'Timestamp' . PHP_EOL . '(leave blank to have this autogenerated)' . PHP_EOL); $nonce = tmhUtilities::read_input(PHP_EOL . 'Nonce' . PHP_EOL . '(leave blank to have this autogenerated)' . PHP_EOL); $url = tmhUtilities::read_input(PHP_EOL . 'URL' . PHP_EOL . '(e.g. https://api.twitter.com/1/account/verify_credentials.json)' . PHP_EOL); $action = tmhUtilities::read_input(PHP_EOL . 'HTTP Action' . PHP_EOL . '(leave blank for GET)' . PHP_EOL); $tmhOAuth = new tmhOAuth(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'user_token' => $user_token, 'user_secret' => $user_secret, 'prevent_request' => true)); if (strlen($nonce) > 0) { $tmhOAuth->config['force_nonce'] = true; $tmhOAuth->config['nonce'] = $nonce; } if (strlen($timestamp) > 0) { $tmhOAuth->config['force_timestamp'] = true; $tmhOAuth->config['timestamp'] = $timestamp; } $action = strlen($action) > 0 ? strtoupper($action) : 'GET'; // default request $tmhOAuth->request($action, $url); // if you want to use paramters you'll need to do something like this: /* $tmhOAuth->request($action, $url, array(
if ($count == $limit) { return true; } return file_exists(dirname(__FILE__) . '/STOP'); } require '../tmhOAuth.php'; require '../tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET', 'user_token' => 'A_USER_TOKEN', 'user_secret' => 'A_USER_SECRET')); $method = 'https://stream.twitter.com/1/statuses/filter.json'; $track = tmhUtilities::read_input('Track terms. For multiple terms separate with commas (leave blank for none): '); $follow = tmhUtilities::read_input('Follow accounts. For multiple accounts separate with commas (leave blank for none): '); $locations = tmhUtilities::read_input('Bounding boxes (leave blank for none): '); $delimited = tmhUtilities::read_input('Delimited? (1,t,true): '); $limit = tmhUtilities::read_input('Stop after how many tweets? (leave blank for unlimited): '); $debug = tmhUtilities::read_input('Debug? (1,t,true): '); $raw = tmhUtilities::read_input('Raw output? (1,t,true): '); $true = array('1', 't', 'true'); $params = array(); if (strlen($track) > 0) { $params['track'] = $track; } if (strlen($follow) > 0) { $params['follow'] = $follow; } if (strlen($locations) > 0) { $params['locations'] = $locations; } if (in_array($delimited, $true)) { $params['delimited'] = 'length'; } if (strlen($limit) > 0) {
<?php date_default_timezone_set('UTC'); require '../tmhOAuth.php'; require '../tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array()); $params = array('q' => 'Search Query', 'since_id' => 'Get results since this ID (or leave blank for earliest allowed)', 'pages' => 'How many pages should be retrieved?', 'rpp' => 'Results per page (default 15)', 'max_id' => 'Max ID to accept. This isn\'t sent to Search but instead used to filter the received results', 'geocode' => 'Geo co-ordinates (e.g. 37.781157,-122.398720,1mi)', 'lang' => 'Restrict results to a specific language? (en,fr,de etc)'); foreach ($params as $k => $v) { $p[$k] = tmhUtilities::read_input("{$v}: "); if (empty($p[$k])) { unset($p[$k]); } } $pages = intval($p['pages']); $pages = $pages > 0 ? $pages : 1; $results = array(); for ($i = 1; $i < $pages; $i++) { $args = array_intersect_key($p, array('q' => '', 'since_id' => '', 'rpp' => '', 'geocode' => '', 'lang' => '')); $args['page'] = $i; $tmhOAuth->request('GET', 'http://search.twitter.com/search.json', $args, false); echo "Received page {$i}\t{$tmhOAuth->url}" . PHP_EOL; if ($tmhOAuth->response['code'] == 200) { $data = json_decode($tmhOAuth->response['response'], true); foreach ($data['results'] as $tweet) { $results[$tweet['id_str']] = $tweet; } } else { $data = htmlentities($tmhOAuth->response['response']); echo 'There was an error.' . PHP_EOL; var_dump($data); break;
EOM; } else { echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL; die; } } function access_token($tmhOAuth, $pin) { $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => trim($pin))); if ($code == 200) { $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']); // print tokens echo <<<EOM Congratulations, below is the user token and secret for {$oauth_creds['screen_name']}. Use these to make authenticated calls to Twitter using the application with consumer key: {$tmhOAuth->config['consumer_key']} User Token: {$oauth_creds['oauth_token']} User Secret: {$oauth_creds['oauth_token_secret']} EOM; } else { echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL; } var_dump($tmhOAuth); die; } welcome(); request_token($tmhOAuth); $pin = tmhUtilities::read_input('What was the Pin Code?: '); access_token($tmhOAuth, $pin);