简体   繁体   中英

is it possible to post stories to facebook page wall from my website without logging in to facebook?

Here is the code i used to post stories to facebook page wall from my website. i have installed facebook sdk like facebook.php and base_facebook.php etc files.My requirement is to post stories without logging into facebook.i have gone through many tutorials yet i couldnt find any solution for this .can you please help me in this.here is the code which i am using.

$appid = 'xxxxx'; //Application ID
$appsec = 'xxxxx'; // Application secret
$redirectUrl = 'http://test.com/admin/'; //Facebook redirects back to this page
$permissions = 'publish_stream'; // Permissions we will need



 if(isset($_POST['FacebookPageID']) && strlen($_POST['FacebookPageID'])>10)
 {

 $_SESSION['FacebookPageID']=$_POST['FacebookPageID'];
 $_SESSION['FacebookMessage']=$_POST['FacebookMessage'];
 $_SESSION['FacebookTitle']=$_POST['FacebookTitle'];

 }

 if(!is_numeric($_SESSION['FacebookPageID']) || strlen($_SESSION['FacebookPageID'])<5)
 {

  die("<meta http-equiv=\"refresh\" content=\"2;URL=".$redirectUrl."\" />");
  }
 else
 {

 if(!isset($_GET["code"]))
 {


  $_SESSION['state'] = md5(uniqid(rand(), TRUE));

  $RedirectToFacebook = "https://www.facebook.com/dialog/oauth?client_id=".$appid;
  $RedirectToFacebook .="&redirect_uri=".urlencode($redirectUrl.'test.php');

     die("<script type=\"text/javascript\">top.location.href='" . $RedirectToFacebook .                 </script>
  <noscript><a href='".$RedirectToFacebook."'>Needs Permissioins</a></noscript>");
}
else
{

############## Facebook Page ID ############
$facebookPageID = $_SESSION['FacebookPageID']; 


############## Wall Message ############
$facebookMessage = (empty($_SESSION['FacebookMessage']) ||    s      trlen($_SESSION['FacebookMessage'])<5)?"Nice Facebook Wall Posting     Script!":$_SESSION['FacebookMessage'];

 $facebookTitle = (empty($_SESSION['FacebookTitle']) ||     strlen($_SESSION['FacebookTitle'])<5)?"Nice Facebook Wall Posting  Script!":$_SESSION['FacebookTitle'];


 if($_SESSION['state'] !="")
{
echo $_SESSION['state'];

  // $siteurl=$_GET['realurl'];
  $AccessTokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=".$appid;
  $AccessTokenUrl .="&redirect_uri=".urlencode($redirectUrl.'test.php');
 $AccessTokenUrl .="&client_secret=".$appsec;
 $AccessTokenUrl .="&code=".$_GET["code"];
 $ReturnedString = file_get_contents($AccessTokenUrl);
 $params=null;
 parse_str($ReturnedString, $params);
 $OurAccessToken = $params['access_token']; //access token

 //---------------
 require_once('src/facebook.php' ); //Include our facebook Php Sdk

$post_url = '/'.$facebookPageID.'/feed';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsec,
 ));

 //the Posting Parameters
$PostData = array(
'message' =>$facebookMessage,
'name' => $_SESSION['title'],
'caption' => "testcom",
'link' => 'from tranz',
'description' => $facebookMessage,
' picture' => "http://test/uploads/".$_SESSION['imageshare']."",
'access_token' =>$OurAccessToken,
'actions' => array(
 array(
'name' => 'Saaraan',
'link' => 'http://www.saaraan.com'
 )
 )
 );

 //print_r($PostData); exit;

 try {
$result = $facebook->api($post_url, 'post', $PostData);
 //$result = $facebook->api('me/feed','post', $PostData);
 if($result)
 {
// session_destroy();
 echo 'Done..';
 die("<meta http-equiv=\"refresh\" content=\"2;URL=".$redirectUrl."?  success=1&fbp=".$facebookPageID."\" />");
  }
 }
 catch (Exception $e)
 {
echo 'Facebook could be experiencing some problem! Try again later <br />Facebook   Says: '. $e->getMessage();
 }
 //--------------
 }
}

Facebook requires users to be authenticated to post something. No, it is not possible to post without authentication, if authentication is what you mean by "logging in."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM