我已经集成了twitter连接与我的网站。我使用了oauth代码在twitter上发帖。我已经提到了我在下面使用的部分代码。
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
// Your Message
$message = "hi I am fine";
// Send tweet
$tweet->post('statuses/update', array('status' => "$message"));
但是我不能在登录的用户页面上发布,它只显示在应用程序的用户页面上,我应该用这个代码添加任何东西吗?如果是这样,请让我知道我应该用代码做什么。
我已经通过JS做到了这一点。那可能对你有帮助。
代码是这样的:
与推特分享:
<script type="text/javascript">
function twitter_click()
{u=location.href;t=document.title;window.open(
'http://twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t),'sharer',
'toolbar=0,status=0,width=626,height=436');return false;}</script>
<a href="javascript:void(0);" onclick="return twitter_click()">
<img alt="twittershare" src="http://lh6.ggpht.com/_iEnxos6ddpE/Tb6BVrptRVI/AAAAAAAACaU/XQ0dT77GozI/tweetsip.gif"/></a>
与FACEBOOK分享:
<script type="text/javascript">
function fbs_click()
{u=location.href;t=document.title;window.open(
'http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer',
'toolbar=0,status=0,width=626,height=436');return false;}</script>
<a href="javascript:void(0);" onclick="return fbs_click()">
<img alt="facebook share" src="http://lh5.ggpht.com/_iEnxos6ddpE/Tb6BUD0OGfI/AAAAAAAACaQ/0pd1LCCkPDs/SukaFB.gif"/></a>
这段代码没问题。它会成功的。
但最重要的是要找出错误是什么,为什么它不工作。只需替换
$tweet->post('statuses/update', array('status' => "$message"));
使用:$mytweet=$tweet->post('statuses/update', array('status' => "$message"));
var_dump($mytweet);
// print the output coming from the post request, that you done using twitterOauth
我已经使用了相同的代码,第一次它不工作,因为我的应用程序是只读类型,现在工作正常!因此,确保您的应用程序设置至少是Read和Write类型。下面详细介绍解决方案:https://stackoverflow.com/questions/18035906/tweeting-with-php-not-working/18036339#18036339