开发者

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

开发者 https://www.devze.com 2023-03-06 18:55 出处:网络
i am using a twitter script to post messages to the twitter wall from a html form see here: <form name=\"csp_post\" action=\"/test.php\" method=\"post\" >

i am using a twitter script to post messages to the twitter wall from a html form see here:

 <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>

so the twitter will grab whatever i post into the text area and post it onto the wall.

i would like to do the same with facebook. I know there are applications that can do the same thing, but the ones i found uses a different textarea, and i want to use the one i have already.

any ideas? Thanks


You can use the Facebook Graph API for this (documentation: http://developers.facebook.com/docs/reference/api/), specifically the following function: http://developers.facebook.com/docs/reference/api/post/

Read the bottom of the page, the block named Publishing, this should do what you want.

To authenticate using the account to your choice, you will have to use OAuth (http://developers.facebook.com/docs/authentication/); this is rather complex so I would highly recommend using a library for this, preferably Facebooks own PHP Library: https://github.com/facebook/php-sdk/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号