Webサイトに、ユーザーが編集できる最大140文字のテキストエリアがあります。2つの送信ボタンがあります。1つはFacebookに投稿するためのもので、もう1つはTwitterに投稿するためのものです。Facebookボタンを正常に機能させることができましたが、Twitterボタンで途中で立ち往生しています。
ユーザーがボタンをクリックしてツイートした時点では、自分のアカウントにのみツイートすることができます。これをユーザーのアカウントに移動させたい。これは、PHPでoAuthToken / Secretを定義しているためですが、ユーザーのサインイン/アプリの承認をリクエストして、oAuth情報を作成して使用する方法がわかりません。ここや他の場所で自分に合った答えを見つけることができないようですので、助けや正しい方向へのポイントがあれば素晴らしいです!
これまでの私のコードは次のとおりです。
<?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 -->