PHP,如何从自定义文本区域发布到Facebook


php ,how to post to facebook from a custom textarea?

我正在使用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做同样的事情。我知道有些应用程序可以做同样的事情,但我发现的应用程序使用不同的文本区域,我想使用我已经拥有的应用程序。

有什么想法吗?谢谢

您可以使用Facebook Graph API(文档:http://developers.facebook.com/docs/reference/api/),特别是以下功能:http://developers.facebook.com/docs/reference/api/post/

阅读页面底部,名为"发布"的块,这应该可以做你想要的。

要使用您选择的帐户进行身份验证,您必须使用OAuth(http://developers.facebook.com/docs/authentication/);这相当复杂,所以我强烈建议为此使用库,最好是Facebook自己的PHP库:https://github.com/facebook/php-sdk/