I have a textarea on my website that a user can edit, with a maximum of 140 characters. I have two submit buttons - one to post to Facebook, one for posting to Twitter. I was able to get the Facebook button working okay, but I'm stuck halfway with the Twitter button.
At the moment when a user clicks on the button to tweet, I can only get it to tweet to my own account. I want this to go to the user's account. I realize this is because I define my oAuthToken / Secret in my PHP, but I am not sure how to request for a user sign in / authorize my app and therefore creating and using their oAuth info. I can't seem to find an answer that works for me here or anywhere else so some help or a point in the right direction would be great!
Here's my code so far:
<?php if($_SERVER['REQUEST_METHOD'] == "POST") { ?>
<?php $statusupdate = $_POST['text']; ?>
<?php $socialsubmit = $_POST['socialsubmit']; ?>
<?php if($socialsubmit == "share") { ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '182922938522212', // App ID
channelUrl : 'channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.ui({
method: 'feed',
name: 'Minty Delivers',
caption: 'Same Day Grocery Delivery in Halifax',
description: '<?php echo $statusupdate; ?>',
link: 'http://www.mintydelivers.com',
picture: 'http://www.mintydelivers.com/connect-share.png'
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<?php echo $socialsubmit;?>
<?php } else if($socialsubmit == "tweet") { ?>
<?php
$consumerKey = 'xxx';
$consumerSecret = 'xxx';
$oAuthToken = 'xxx';
$oAuthSecret = 'xxx';
require_once('tw/twitteroauth.php');
// create a new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
//send a tweet
$tweet->post('statuses/update', array('status' => $statusupdate));
?>
<div class="alert alert-success">
Your tweet was successfully posted. Thanks for sharing!
</div>
<?php } ?>
<?php } ?>
<form id="status-update" action=""; method="post">
<textarea name="text" onKeyPress="return charLimit(this)" onKeyUp="return characterCount(this)">I found this GREAT company called Minty that delivers groceries, wine, flowers and gifts anywhere in Halifax! www.mintydelivers.com</textarea>
<p><span id="charCount">9</span> characters left</p>
<button id="twitter" class="tweetpopup" name="socialsubmit" value="tweet" type="submit">Tweet This</button>
<button id="facebook" name="socialsubmit" value="share" type="submit">Share This</button>
</form><!-- end form -->