我正在使用twitter脚本将消息从html表单发布到twitter墙上,请参阅此处:
<form name="csp_post" action="/test.php" method="post" >
<textarea name="text" id="text" rows="3" cols="64" ></textarea>
<input type="hidden" name="action" value="post">
<?php session_start();
include 'twitter-oauth/lib/EpiCurl.php';
include 'twitter-oauth/lib/EpiOAuth.php';
include 'twitter-oauth/lib/EpiTwitter.php';
include 'twitter-oauth/lib/secret.php';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
if(isset($_SESSION['oauth_token'])){
$oauth_token = $_SESSION['oauth_token'];
}
else {
$oauth_token = $_GET['oauth_token'];
$_SESSION['oauth_token']=$_GET['oauth_token'];
}
$oauth_token = $_GET['oauth_token'];
if($oauth_token == '')
{
$url = $twitterObj->getAuthorizationUrl();
echo "<div style='width:auto;margin-top:10px;margin-left:10px;margin-right:auto'>";
echo "<a href='$url'>Sign In with Twitter to post Comments</a>";
echo "</div>";
}
else
{
echo "<div style='width:auto;margin-top:10px;margin-left:10px;margin-right:auto'>";
echo "Your comments are now being posted on Twitter";
echo "</div>";
$twitterObj->setToken($_GET['oauth_token']);
$token = $twitterObj->getAccessToken();
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
$_SESSION['ot'] = $token->oauth_token;
$_SESSION['ots'] = $token->oauth_token_secret;
$twitterInfo= $twitterObj->get_accountVerify_credentials();
$twitterInfo->response;
$username = $twitterInfo->screen_name;
$profilepic = $twitterInfo->profile_image_url;
}
if(isset($_POST['cssp']))
{
$msg = $_REQUEST['text'];
$twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);
$update_status = $twitterObj->post_statusesUpdate(array('status' => $msg));
$temp = $update_status->response;
echo "<div align='center'>Updated your Timeline Successfully .</div>";
}
?>
<input type='image' src='../images/123.gif' rel='submit' border='0' value='Tweet' name='cssp' id='cssp' alt='Share'/>
</form>所以twitter会抓取我在文本区发布的任何内容,并将其发布到墙上。
我也想用facebook做同样的事情。我知道有些应用程序可以做同样的事情,但我找到的应用程序使用了不同的文本区域,我想使用我已经拥有的那个。
有什么想法吗?谢谢
发布于 2011-05-18 01:12:30
为此,您可以使用Facebook Graph API (文档:http://developers.facebook.com/docs/reference/api/),特别是以下函数:http://developers.facebook.com/docs/reference/api/post/
阅读页面底部的名为Publishing的块,这应该可以做你想做的事情。
要使用您选择的帐户进行身份验证,您必须使用OAuth (http://developers.facebook.com/docs/authentication/);这相当复杂,因此我强烈建议使用一个库,最好是Facebook自己的PHP:https://github.com/facebook/php-sdk/
https://stackoverflow.com/questions/6034282
复制相似问题