Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- //pass session variables into standard variable
- $ck = $_SESSION['consumer_key'];
- $cs = $_SESSION['consumer_secret'];
- $at = $_SESSION['access_token'];
- $ats = $_SESSION['access_token_secret'];
- $hashtag = $_SESSION['hashtag'];
- $tweet = $_POST['tweet'];
- //TODO unset session at end of script
- //TODO limit tweet length
- if (!empty($ck && $cs && $at && $ats && $tweet)){
- $ck = $_POST['consumer_key'] = $ck; //get session value into POST then pass back to variable
- $cs = $_POST['consumer_secret'] = $cs;
- $at = $_POST['access_token'] = $at;
- $ats = $_POST['access_token_secret'] = $ats;
- $_POST['tweet'];
- $hashtag = $_POST['hashtag'] = $hashtag;
- }
- require "autoload.php";
- use Abraham\TwitterOAuth\TwitterOAuth;
- define('CONSUMER_KEY', $ck); // add app consumer key between single quotes
- define('CONSUMER_SECRET', $cs); // add app consumer secret key between single quotes
- $access_token = $at;
- $access_token_secret = $ats;
- $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
- if (!empty($ck && $cs && $at && $ats && $tweet && $hashtag)) {
- $hashtag = '#' . $hashtag;
- $connection->post('statuses/update',array('status' => $tweet . ' ' . $hashtag));
- $t = $connection;
- echo '<pre>';
- //print_r($t);
- echo '</pre>';
- echo "Your message has been sent to Twitter with a hashtag.";
- }
- //TODO Add error handling to send to special inbox
- //Tweet without hashtags
- if (!empty($ck && $cs && $at && $ats && $tweet) && empty($hashtag)) {
- $connection->post('statuses/update',array('status' => $tweet));
- //$t = $connection;
- //echo '<pre>';
- //print_r($t);
- //echo '</pre>';
- //echo "Your message has been sent to Twitter without a hashtag.";
- }
- session_destroy(); //this will hopefully help with load on this file
- ?>
Advertisement
Add Comment
Please, Sign In to add comment