Guest User

Untitled

a guest
Feb 18th, 2016
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. <?php
  2. session_start();
  3. //pass session variables into  standard variable
  4. $ck = $_SESSION['consumer_key'];
  5. $cs = $_SESSION['consumer_secret'];
  6. $at = $_SESSION['access_token'];
  7. $ats = $_SESSION['access_token_secret'];
  8. $hashtag = $_SESSION['hashtag'];
  9. $tweet = $_POST['tweet'];
  10.  
  11. //TODO unset session at end of script
  12. //TODO limit tweet length
  13.  
  14. if (!empty($ck && $cs && $at && $ats && $tweet)){
  15.   $ck = $_POST['consumer_key'] = $ck; //get session value into POST then pass back to variable
  16.   $cs = $_POST['consumer_secret'] = $cs;
  17.   $at = $_POST['access_token'] = $at;
  18.   $ats = $_POST['access_token_secret'] = $ats;
  19.   $_POST['tweet'];
  20.   $hashtag = $_POST['hashtag'] = $hashtag;
  21. }
  22.  
  23.  
  24. require "autoload.php";
  25.  
  26. use Abraham\TwitterOAuth\TwitterOAuth;
  27.  
  28. define('CONSUMER_KEY', $ck); // add app consumer key between single quotes
  29. define('CONSUMER_SECRET', $cs); // add app consumer secret key between single quotes
  30. $access_token = $at;
  31. $access_token_secret = $ats;
  32.  
  33. $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
  34.  
  35. if (!empty($ck && $cs && $at && $ats && $tweet && $hashtag)) {
  36.  
  37.   $hashtag = '#' . $hashtag;
  38.   $connection->post('statuses/update',array('status' => $tweet . ' ' . $hashtag));
  39.   $t = $connection;
  40.   echo '<pre>';
  41.   //print_r($t);
  42.   echo '</pre>';
  43.   echo "Your message has been sent to Twitter with a hashtag.";
  44. }
  45.  
  46. //TODO Add error handling to send to special inbox
  47.  
  48.  
  49. //Tweet without hashtags
  50.  
  51. if (!empty($ck && $cs && $at && $ats && $tweet) && empty($hashtag)) {
  52.   $connection->post('statuses/update',array('status' => $tweet));
  53.   //$t = $connection;
  54.   //echo '<pre>';
  55.   //print_r($t);
  56.   //echo '</pre>';
  57.   //echo "Your message has been sent to Twitter without a hashtag.";
  58. }
  59.  
  60. session_destroy(); //this will hopefully help with load on this file
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment