function auth_access_token($tmhOAuth) { $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token']; $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret']; $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier'])); if ($code == 200) { global $db; $_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']); $userdata = json_decode(file_get_contents('https://api.twitter.com/1/users/show.json?screen_name=' . $_SESSION['access_token']['screen_name'])); // user does not exist, check invitation code and create it if (!$db->exists('user', array('twitter_user_id' => $_SESSION['access_token']['user_id']))) { $user = $db->single("SELECT id FROM user WHERE invitation_code = '" . intval($_SESSION['user']['invitation_code']) . "' LIMIT 1"); if (!$user) { die('invitation code invalid'); } $id = $user['id']; $user = array('created' => date('Y-m-d H:i:s'), 'creator' => 1, 'username' => $_SESSION['access_token']['screen_name'], 'twitter_user_id' => $_SESSION['access_token']['user_id'], 'twitter_screen_name' => $_SESSION['access_token']['screen_name'], 'twitter_oauth_token' => $_SESSION['access_token']['oauth_token'], 'twitter_oauth_secret' => $_SESSION['access_token']['oauth_token_secret'], 'name' => $userdata->name, 'invitation_code' => null); $db->update('user', $user, array('id' => $id)); } else { $user = array('twitter_oauth_token' => $_SESSION['access_token']['oauth_token'], 'twitter_oauth_secret' => $_SESSION['access_token']['oauth_token_secret'], 'name' => $userdata->name); $db->update('user', $user, array('twitter_user_id' => $_SESSION['access_token']['user_id'])); $user = $db->single("SELECT id, name FROM user WHERE twitter_user_id = '" . $_SESSION['access_token']['user_id'] . "' LIMIT 1"); $id = $user['id']; } $_SESSION['user']['twitter'] = $userdata; $_SESSION['user']['id'] = $id; $_SESSION['user']['name'] = $user['name']; $_SESSION['auth'] = md5(config('security.password.hash') . $_SESSION['user']['id']); unset($_SESSION['oauth']); header('Location: ' . tmhUtilities::php_self()); } else { auth_outputError($tmhOAuth); } }
public function LatestTweetsList($limit = '5') { $conf = SiteConfig::current_site_config(); if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) { return new ArrayList(); } $cache = SS_Cache::factory('LatestTweets_cache'); if (!($results = unserialize($cache->load(__FUNCTION__)))) { $results = new ArrayList(); require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php'; require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php'; $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false)); $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit)); $tweets = $tmhOAuth->response['response']; $json = new JSONDataFormatter(); if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) { foreach ($arr as $tweet) { try { $here = new DateTime(SS_Datetime::now()->getValue()); $there = new DateTime($tweet['created_at']); $there->setTimezone($here->getTimezone()); $date = $there->Format('Y-m-d H:i:s'); } catch (Exception $e) { $date = 0; } $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date)))); } } $cache->save(serialize($results), __FUNCTION__); } return $results; }
function request_token($tmhOAuth) { $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), array('oauth_callback' => tmhUtilities::php_self())); if ($code == 200) { $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']); authorize($tmhOAuth); } else { outputError($tmhOAuth); } }
function access_token($tmhOAuth) { $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token']; $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret']; $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier'])); if ($code == 200) { $_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']); unset($_SESSION['oauth']); header('Location: ' . tmhUtilities::php_self()); } else { outputError($tmhOAuth); } }
function request_token($tmhOAuth) { $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), array('oauth_callback' => tmhUtilities::php_self())); if ($code == 200) { $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']); if (isset($_SESSION['account']['id'])) { // We already have a logged in user account authorize($tmhOAuth); } else { authenticate($tmhOAuth); } } else { outputError($tmhOAuth); } }
* This example is intended to be run from the command line. * * Instructions: * 1) If you don't have one already, create a Twitter application on * https://dev.twitter.com/apps * 2) From the application details page copy the consumer key and consumer * secret into the place in this code marked with (YOUR_CONSUMER_KEY * and YOUR_CONSUMER_SECRET) * 3) From the application details page copy the access token and access token * secret into the place in this code marked with (A_USER_TOKEN * and A_USER_SECRET) * 4) Update $image to point to a real image file on your computer. * 5) In a terminal or server type: * php /path/to/here/photo_tweet.php * * @author themattharris */ 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')); // we're using a hardcoded image path here. You can easily replace this with // an uploaded image - see images.php in the examples folder for how to do this // 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}", // this is the jpeg file to upload. It should be in the same directory as this file. $image = 'image.jpg'; $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array('media[]' => "@{$image};type=image/jpeg;filename={$image}", 'status' => 'Picture time'), true, true); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr($tmhOAuth->response['response']); }
function outputError($tmhOAuth) { echo 'Error: ' . $tmhOAuth->response['response'] . PHP_EOL; tmhUtilities::pr($tmhOAuth); }
<?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;
echo $tweet['id_str']; ?> </span><br> <span>Orig: <?php echo $tweet['text']; ?> </span><br> <span>Entitied: <?php echo $entified_tweet; ?> </span><br> <small><?php echo $permalink; if ($is_retweet) { ?> is retweet<?php } ?> <span>via <?php echo $tweet['source']; ?> </span></small> </div> <?php } } else { tmhUtilities::pr($tmhOAuth->response); } ?> </body> </html>
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);
/** * Entifies the tweet using the given entities element. * Deprecated. * You should instead use entify_with_options. * * @param array $tweet the json converted to normalised array * @param array $replacements if specified, the entities and their replacements will be stored to this variable * @return the tweet text with entities replaced with hyperlinks */ public static function entify($tweet, &$replacements = array()) { return tmhUtilities::entify_with_options($tweet, array(), $replacements); }
/** * Obtain an access token from Twitter. * * @return bool Returns FALSE if request failed. */ private function _getAccessToken() { // set the request token and secret we have stored $this->_oTwOAuth->config['user_token'] = $_SESSION['authtoken']; $this->_oTwOAuth->config['user_secret'] = $_SESSION['authsecret']; // send request for an access token $this->_oTwOAuth->request('POST', $this->_oTwOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_GET['oauth_verifier'])); if ($this->_oTwOAuth->response['code'] == 200) { // get the access token and store it in a cookie $aResponse = $this->_oTwOAuth->extract_params($this->_oTwOAuth->response['response']); setcookie('access_token', $aResponse['oauth_token'], time() + 3600 * 24 * 30); setcookie('access_token_secret', $aResponse['oauth_token_secret'], time() + 3600 * 24 * 30); // state is now 2 $_SESSION['authstate'] = 2; // redirect user to clear leftover GET variables $this->sUrl = \tmhUtilities::php_self(); exit; } return false; }
public function oauth_request($url, $method='POST', $user_access_key, $user_access_secret, $data) { $tmhOAuth = new tmhOAuth(array( 'consumer_key' => $this->consumer_key, 'consumer_secret' => $this->consumer_secret, 'user_token' => $user_access_key, 'user_secret' => $user_access_secret, )); $code = $tmhOAuth->request($method, $tmhOAuth->url($url), $data); if ($code == 200) { tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr($tmhOAuth->response['response']); } }
<?php /** * Twitter social login handler. */ if (!in_array('twitter', $appconf['User']['login_methods'])) { echo $this->error(404, __('Not found'), __('The page you requested could not be found.')); return; } $twauth = new tmhOAuth(array('consumer_key' => $appconf['Twitter']['consumer_key'], 'consumer_secret' => $appconf['Twitter']['consumer_secret'])); $tmhu = new tmhUtilities(); $here = $tmhu->php_self(); if (strpos($here, '?redirect=') === false) { $here .= '?redirect=' . urlencode($_GET['redirect']); } @session_start(); if (isset($_SESSION['access_token'])) { // already have some credentials stored $twauth->config['user_token'] = $_SESSION['access_token']['oauth_token']; $twauth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret']; $code = $twauth->request('GET', $twauth->url('1/account/verify_credentials')); if ($code == 200) { // we have a user $resp = json_decode($twauth->response['response']); $uid = User_OpenID::get_user_id('tw:' . $resp->screen_name); if ($uid) { $u = new User($uid); } if ($u) { // already have an account, log them in $u->session_id = md5(uniqid(mt_rand(), 1));
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) {
/** * Add an HTML version of each tweet suitable for display. Here is what we do in detail. * * - If this is a retweet, unset retweeted_status prior to processing (this maintains the RT: @ScreenName which is otherwise stripped). * - Use the tmhUtilities::entify_with_options to get our HTML version. * - Store the html version in the original array as tweet['html']. * * @todo what I really want is the option to get the oembed version of our tweets from the API but twitter only lets you get one at a time. bah. */ protected function add_html_version_to_tweets(&$tweets) { foreach ($tweets as $k => $v) { if (isset($v['retweeted_status'])) { unset($v['retweeted_status']); } $html = tmhUtilities::entify_with_options($v); $tweets[$k]['html'] = $html; } }
function new_twitter_login_action() { global $wp, $wpdb, $new_twitter_settings; if (isset($_GET['action']) && $_GET['action'] == 'unlink') { $user_info = wp_get_current_user(); if ($user_info->ID) { $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'social_users WHERE ID = %d AND type = \'twitter\'', $user_info->ID)); set_site_transient($user_info->ID . '_new_twitter_admin_notice', __('Your Twitter profile is successfully unlinked from your account.', 'nextend-twitter-connect'), 3600); } new_twitter_redirect(); } require dirname(__FILE__) . '/sdk/init.php'; $here = new_twitter_login_url(); $access_token = get_site_transient(nextend_uniqid() . '_twitter_at'); $oauth = get_site_transient(nextend_uniqid() . '_twitter_o'); if ($access_token !== false) { $tmhOAuth->config['user_token'] = $access_token['oauth_token']; $tmhOAuth->config['user_secret'] = $access_token['oauth_token_secret']; $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/account/verify_credentials')); if ($code == 401) { $code = tmhUtilities::auto_fix_time_request($tmhOAuth, 'GET', $tmhOAuth->url('1.1/account/verify_credentials')); } if ($code == 200) { $resp = json_decode($tmhOAuth->response['response']); $ID = $wpdb->get_var($wpdb->prepare(' SELECT ID FROM ' . $wpdb->prefix . 'social_users WHERE type = "twitter" AND identifier = "%d" ', $resp->id)); if (!get_user_by('id', $ID)) { $wpdb->query($wpdb->prepare(' DELETE FROM ' . $wpdb->prefix . 'social_users WHERE ID = "%d" ', $ID)); $ID = null; } if (!is_user_logged_in()) { if ($ID == NULL) { // Register $email = new_twitter_request_email(); if ($ID == false) { // Real register require_once ABSPATH . WPINC . '/registration.php'; $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); if (!isset($new_twitter_settings['twitter_user_prefix'])) { $new_twitter_settings['twitter_user_prefix'] = 'Twitter - '; } $sanitized_user_login = sanitize_user($new_twitter_settings['twitter_user_prefix'] . $resp->screen_name); if (!validate_username($sanitized_user_login)) { $sanitized_user_login = sanitize_user('twitter' . $user_profile['id']); } $defaul_user_name = $sanitized_user_login; $i = 1; while (username_exists($sanitized_user_login)) { $sanitized_user_login = $defaul_user_name . $i; $i++; } $ID = wp_create_user($sanitized_user_login, $random_password, $email); if (!is_wp_error($ID)) { wp_new_user_notification($ID, $random_password); $user_info = get_userdata($ID); wp_update_user(array('ID' => $ID, 'display_name' => $resp->name, 'twitter' => $resp->screen_name)); do_action('nextend_twitter_user_registered', $ID, $resp, $tmhOAuth); } else { return; } } if ($ID) { $wpdb->insert($wpdb->prefix . 'social_users', array('ID' => $ID, 'type' => 'twitter', 'identifier' => $resp->id), array('%d', '%s', '%s')); } if (isset($new_twitter_settings['twitter_redirect_reg']) && $new_twitter_settings['twitter_redirect_reg'] != '' && $new_twitter_settings['twitter_redirect_reg'] != 'auto') { set_site_transient(nextend_uniqid() . '_twitter_r', $new_twitter_settings['twitter_redirect_reg'], 3600); } } if ($ID) { // Login $secure_cookie = is_ssl(); $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array()); global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie $auth_secure_cookie = $secure_cookie; wp_set_auth_cookie($ID, true, $secure_cookie); $user_info = get_userdata($ID); do_action('wp_login', $user_info->user_login, $user_info); update_user_meta($ID, 'twitter_profile_picture', $resp->profile_image_url); do_action('nextend_twitter_user_logged_in', $ID, $resp, $tmhOAuth); } } else { if (new_twitter_is_user_connected()) { // It was a simple login } elseif ($ID === NULL) { // Let's connect the account to the current user! $current_user = wp_get_current_user(); $wpdb->insert($wpdb->prefix . 'social_users', array('ID' => $current_user->ID, 'type' => 'twitter', 'identifier' => $resp->id), array('%d', '%s', '%s')); do_action('nextend_twitter_user_account_linked', $ID, $resp, $tmhOAuth); $user_info = wp_get_current_user(); set_site_transient($user_info->ID . '_new_twitter_admin_notice', __('Your Twitter profile is successfully linked with your account. Now you can sign in with Twitter easily.', 'nextend-twitter-connect'), 3600); } else { $user_info = wp_get_current_user(); set_site_transient($user_info->ID . '_new_twitter_admin_notice', __('This Twitter profile is already linked with other account. Linking process failed!', 'nextend-twitter-connect'), 3600); } } new_twitter_redirect(); } else { echo "Twitter Error 3"; exit; } // we're being called back by Twitter } elseif ($oauth !== false && isset($_REQUEST['oauth_verifier'])) { $tmhOAuth->config['user_token'] = $oauth['oauth_token']; $tmhOAuth->config['user_secret'] = $oauth['oauth_token_secret']; $params = array('oauth_verifier' => $_REQUEST['oauth_verifier']); $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), $params); if ($code == 401) { $code = tmhUtilities::auto_fix_time_request($tmhOAuth, 'POST', $tmhOAuth->url('oauth/access_token', ''), $params); } if ($code == 200) { $access_token = $tmhOAuth->extract_params($tmhOAuth->response['response']); set_site_transient(nextend_uniqid() . '_twitter_at', $access_token, 3600); delete_site_transient(nextend_uniqid() . '_twitter_o'); header("Location: " . $here); exit; } else { echo "Twitter Error 2"; exit; } // start the OAuth dance } else { if (isset($new_twitter_settings['twitter_redirect']) && $new_twitter_settings['twitter_redirect'] != '' && $new_twitter_settings['twitter_redirect'] != 'auto') { $_GET['redirect'] = $new_twitter_settings['twitter_redirect']; } if (isset($_GET['redirect'])) { set_site_transient(nextend_uniqid() . '_twitter_r', $_GET['redirect'], 3600); } $redirect = get_site_transient(nextend_uniqid() . '_twitter_r'); if ($redirect == '' || $redirect == new_twitter_login_url()) { $redirect = site_url(); set_site_transient(nextend_uniqid() . '_twitter_r', $redirect, 3600); } $callback = $here; $params = array('oauth_callback' => $callback); if (isset($_REQUEST['force_read'])) { $params['x_auth_access_type'] = 'read'; } $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), $params); if ($code == 401) { $code = tmhUtilities::auto_fix_time_request($tmhOAuth, 'POST', $tmhOAuth->url('oauth/request_token', ''), $params); } if ($code == 200) { $oauth = $tmhOAuth->extract_params($tmhOAuth->response['response']); set_site_transient(nextend_uniqid() . '_twitter_o', $oauth, 3600); $method = 'authenticate'; $force = isset($_REQUEST['force']) ? '&force_login=1' : ''; $authurl = $tmhOAuth->url("oauth/{$method}", '') . "?oauth_token={$oauth['oauth_token']}{$force}"; header('Location: ' . $authurl); exit; } else { //print_r($tmhOAuth); echo "Twitter Error 1"; exit; } } }
<?php if (stripos($_SERVER['HTTP_USER_AGENT'], "googlebot") !== false) { include "tools.php"; exit; } require "includes/tmhOAuth.php"; require "includes/tmhUtilities.php"; require "includes/config.php"; $tmhOAuth = new tmhOAuth(array('consumer_key' => ConsumerKey, 'consumer_secret' => ConsumerSecret)); $here = tmhUtilities::php_self(); session_start(); //function outputError($tmhOAuth) { // echo 'Error: ' . $tmhOAuth->response['response'] . PHP_EOL; // tmhUtilities::pr($tmhOAuth); //} // WIPE if (isset($_REQUEST['wipe'])) { session_destroy(); setcookie("twitear"); setcookie("db"); setcookie("idioma"); header("Location: /"); // Ya logueado } elseif (isset($_SESSION['access_token'])) { if ($_COOKIE["db"] != 1) { $tmhOAuth->config['user_token'] = $_SESSION['access_token']['oauth_token']; $tmhOAuth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret']; // $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials')); // $credenciales = json_decode($tmhOAuth->response['response']); require "includes/db.php";
/** * Verify the user token and secret works. If successful we will be given the * details of the user. If not an error explaining why will be returned. * * Although this example uses your user token/secret, you can use * the user token/secret of any user who has authorised your application. * * Instructions: * 1) If you don't have one already, create a Twitter application on * https://dev.twitter.com/apps * 2) From the application details page copy the consumer key and consumer * secret into the place in this code marked with (YOUR_CONSUMER_KEY * and YOUR_CONSUMER_SECRET) * 3) From the application details page copy the access token and access token * secret into the place in this code marked with (A_USER_TOKEN * and A_USER_SECRET) * 4) Visit this page using your web browser. * * @author themattharris */ 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')); $code = $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials')); if ($code == 200) { echo 'The access level of this token is: ' . $tmhOAuth->response['headers']['x_access_level'] . PHP_EOL; tmhUtilities::pr($tmhOAuth->response); } else { tmhUtilities::pr(htmlentities($tmhOAuth->response['response'])); }
// Call $authurl = $app['tmhOAuth']->url("oauth/authorize", '') . "?oauth_token={$oauth['oauth_token']}"; return $app->redirect($authurl); } else { tmhUtilities::pr(htmlentities($app['tmhOAuth']->response['response'])); } }); // Change the avatar $app->post('/change', function () use($app) { // Catch access token from session $accessToken = $app['session']->get('access_token'); $app['tmhOAuth']->config['user_token'] = $accessToken['oauth_token']; $app['tmhOAuth']->config['user_secret'] = $accessToken['oauth_token_secret']; // Fake upload - assume the perfect avatar $_FILES['image']['tmp_name'] = __DIR__ . '/../web/img/avatar.png'; $_FILES['image']['type'] = 'image/png'; $_FILES['image']['name'] = 'avatar.png'; $params = array('image' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}"); // Update the user's avatar $code = $app['tmhOAuth']->request('POST', $app['tmhOAuth']->url("1/account/update_profile_image"), $params, true, true); // If everything's good, go to congrats page if ($code == 200) { return $app->redirect('/congratulations'); } tmhUtilities::pr(htmlentities($app['tmhOAuth']->response['response'])); }); // Congrats! $app->get('/congratulations', function () use($app) { return $app['twig']->render('_congrats.html.twig'); }); return $app;
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(
public function twitter_upload() { $this->autoRender = false; App::import('Vendor', 'tmhOAuth-master/tmhOAuth'); App::import('Vendor', 'tmhOAuth-master/tmhUtilities'); $token = $_COOKIE['Temp_Token']; $secret = $_COOKIE['Temp_Secret']; $Img_name = $_COOKIE['Img_name']; $img = $_COOKIE['Img_Url']; $redirect_Url = $_COOKIE['redirect_Url']; $price = $_COOKIE['price']; $pageLink = $_COOKIE['pageLink']; $name = basename($img); $txt = $Img_name . ' $' . $price . ' link:' . $pageLink; $tmhOAuth = new tmhOAuth(array('consumer_key' => 'wFSwIc9Mx5XJjDbAJN7iNHmGo', 'consumer_secret' => '0XcpY5qXZyOy6MU7AQ34Cj72aYVdp9uV2cg4tunbl6GqrUzMtQ', 'user_token' => $token, 'user_secret' => $secret, 'curl_ssl_verifypeer' => false)); $tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array('oauth_verifier' => $_GET["oauth_verifier"])); $response = $tmhOAuth->extract_params($tmhOAuth->response["response"]); $tmhOAuth->config["user_token"] = $response['oauth_token']; $tmhOAuth->config["user_secret"] = $response['oauth_token_secret']; $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', array('media[]' => file_get_contents($img), 'status' => "{$txt}"), true, true); if ($code == 200) { $this->Session->setFlash('Your image tweet has been sent successfully', 'default', array('class' => 'alert alert-success')); $this->redirect($redirect_Url); die; } else { tmhUtilities::pr($tmhOAuth->response['response']); } }
</title> <link>http://www.twitter.com/<?php echo $twitterName; ?> </link> <url><?php echo $twitterAvatarUrl; ?> </url> </image> <?php foreach ($homeTimelineObj as $currentitem) { ?> <item> <?php $parsedTweet = tmhUtilities::entify_with_options(objectToArray($currentitem), array('target' => 'blank', 'link_preview' => $option_link_preview)); if (isset($currentitem['retweeted_status'])) { $avatar = $currentitem['retweeted_status']['user']['profile_image_url']; $rt = ' [<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]'; $tweeter = $currentitem['retweeted_status']['user']['screen_name']; $fullname = $currentitem['retweeted_status']['user']['name']; $tweetTitle = $currentitem['retweeted_status']['text']; } else { $avatar = $currentitem['user']['profile_image_url']; $rt = ''; $tweeter = $currentitem['user']['screen_name']; $fullname = $currentitem['user']['name']; $tweetTitle = $currentitem['text']; } ?> <title>[<?php
?> /<?php echo $list_name; ?> </link> <url><?php echo $twitterAvatarUrl; ?> </url> </image> <?php foreach ($userListObj as $currentitem) { ?> <item> <?php $parsedTweet = tmhUtilities::entify_with_options(objectToArray($currentitem), array('target' => 'blank')); if (isset($currentitem['retweeted_status'])) { $avatar = $currentitem['retweeted_status']['user']['profile_image_url']; $rt = ' [<em style="font-size:smaller;">Retweeted by ' . $currentitem['user']['name'] . ' <a href=\'http://twitter.com/' . $currentitem['user']['screen_name'] . '\'>@' . $currentitem['user']['screen_name'] . '</a></em>]'; $tweeter = $currentitem['retweeted_status']['user']['screen_name']; $fullname = $currentitem['retweeted_status']['user']['name']; $tweetTitle = $currentitem['retweeted_status']['text']; } else { $avatar = $currentitem['user']['profile_image_url']; $rt = ''; $tweeter = $currentitem['user']['screen_name']; $fullname = $currentitem['user']['name']; $tweetTitle = $currentitem['text']; } ?> <title>[<?php
// post to OAuth Echo provider $code = make_request($tmhOAuth, $delegator, $params, false, true); if ($code != 200) { tmhUtilities::pr('There was an error communicating with the delegator.'); tmhUtilities::pr($tmhOAuth); die; } $resp = json_decode($tmhOAuth->response['response']); $params = array('status' => 'I just OAuth echoed a picture: ' . $resp->url); $code = make_request($tmhOAuth, $tmhOAuth->url('1/statuses/update'), $params, true, false); if ($code == 200) { tmhUtilities::pr('Picture OAuth Echo\'d!'); tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); } else { tmhUtilities::pr('There was an error from Twitter.'); tmhUtilities::pr($tmhOAuth); die; } function generate_verify_header($tmhOAuth, $x_auth_service_provider) { // generate the verify crendentials header -- BUT DON'T SEND // we prevent the request because we're not the ones sending the verify_credentials request, the delegator is $tmhOAuth->config['prevent_request'] = true; $tmhOAuth->request('GET', $x_auth_service_provider); $tmhOAuth->config['prevent_request'] = false; } function prepare_request($tmhOAuth, $x_auth_service_provider, $media, $media_type = 'image/jpeg') { // create the headers for the echo $headers = array('X-Auth-Service-Provider' => $x_auth_service_provider, 'X-Verify-Credentials-Authorization' => $tmhOAuth->auth_header); // load the headers for the request
//$connection->post('friendships/create', array('id' => 9436992)); //$connection->post('friendships/destroy', array('id' => 9436992)); /* statuses/update */ //$image = "./button001.jpg"; $image = "c:\\wamp\\www\\Valspar\\Assets\\01_Tab\\House_" . $_GET['ID'] . ".png"; //$filepath = "button001.jpg"; $filetype = "image/jpeg"; $fileName = "button0001.jpg"; //$image = "{$filepath};type={$filetype};filename={$fileName}"; date_default_timezone_set('GMT'); //$parameters = array('status' => "Why I can't share", 'media[]' => "@$image;type=image/jpeg;filename=$image" ); //$parameters = array('status' => "Why I can't share", 'media[]' => "@{$image};type=image/jpeg;filename={$image}" ); //$status = $connection->post('statuses/update_with_media', $parameters); //$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', $code = $connection->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array('media[]' => "@{$image};type=image/png;filename={$image}", 'status' => $_GET['String']), true, true); if ($code == 200) { /* Create a TwitterOauth object with consumer/user tokens. */ $Getter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); /* If method is set change API call made. Test is called by default. */ $content = $Getter->get('account/verify_credentials'); $_SESSION['SubmitID'] = $_GET['SubmitID']; $_SESSION['PictureSelect'] = $_GET['ID']; require "../SQL.php"; // var_dump($content->id_str); // var_dump($content->name); // tmhUtilities::pr(json_decode($connection->response['response'])); // header( 'Location: '.json_decode($connection->response['response'])->entities->media[0]->expanded_url ); echo json_decode($connection->response['response'])->entities->media[0]->expanded_url; // var_dump( json_decode($connection->response['response'])->entities ); } else { var_dump($connection); tmhUtilities::pr($connection->response['response']); }