首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php,如何从自定义文本区发布到facebook?

php,如何从自定义文本区发布到facebook?
EN

Stack Overflow用户
提问于 2011-05-18 00:50:39
回答 1查看 1.1K关注 0票数 0

我正在使用twitter脚本将消息从html表单发布到twitter墙上,请参阅此处:

代码语言:javascript
复制
 <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做同样的事情。我知道有些应用程序可以做同样的事情,但我找到的应用程序使用了不同的文本区域,我想使用我已经拥有的那个。

有什么想法吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6034282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档