0
         <?php
          session_start();

         $appid = 'xxxxxxxx'; //Application ID
        $appsec = 'xxxxx'; // Application secret
    $redirectUrl = 'http://test/tester/'; //Facebook redirects back to this page
    $permissions = 'publish_stream,offline_access,read_stream,manage_pages'; // Permissions we will need
    $access_token = '';


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

$_SESSION['FacebookPageID']=$_POST['FacebookPageID'];
$_SESSION['FacebookMessage']=$_POST['FacebookMessage'];
 $_SESSION['Facebooktitle']=$_POST['Facebooktitle'];
 // $_SESSION['image']=$_POST['image'];
}

if(!is_numeric($_SESSION['FacebookPageID']) || strlen($_SESSION['FacebookPageID'])<5)
{
 session_destroy();
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.'process.php');
     $RedirectToFacebook .="&state=".$_SESSION['state'];


  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'];
//$target_path   = $_SESSION['image'];

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


if($_GET['state'] == $_SESSION['state'])
{
$AccessTokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=".$appid;
$AccessTokenUrl .="&redirect_uri=".urlencode($redirectUrl.'process.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' => 'uffcaffnews.com',
 'name' => $Facebooktitle,
 'caption' => "test.fff.com",
 'link' => 'http://www.fff.com/assets/ajax-post-on-page-wall',
'description' => $facebookMessage,
    'picture' => "http://test.c/images/desc.jpg",
'access_token' =>$OurAccessToken,
'actions' => array(
array(
'name' => 'Saaraan',
'link' => 'http://www.saaraan.com'
)
 )
 );

try {

$pageID = '3xxx';
$result = $facebook->api($post_url, 'post', $PostData);


     if($result)
{
 session_destroy();
     echo 'Done..';
 die("<meta http-equiv=\"refresh\" content=\"2;URL=".$redirectUrl."?");
 }
}

我想在不登录 Facebook 帐户的情况下从我的网站管理员将故事发布到 Facebook 页面。请帮助我想从我的网站管理员将故事发布到 Facebook 页面而不登录到 Facebook 帐户。请帮助我

4

1 回答 1

0

您无需offline_access获得向 Facebook 发布内容的权限。只publish_stream需要许可。

即使不需要用户登录。一旦用户授权您的应用程序publish_stream,您就可以开始代表他发布内容,而无需他登录!

你可以参考这里

于 2012-09-06T12:39:47.343 回答