2012-09-06 64 views
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帳戶。請幫助我如何在沒有登錄到php帳戶的情況下將故事發布到Facebook頁面?

回答

0

您不需要offline_access權限即可將內容發佈到Facebook。只需要publish_stream權限。

即使不需要用戶登錄。一旦用戶通過publish_stream權限授權您的應用程序,您可以開始以他的名義發佈內容而不需要他需要登錄!您可以參考here

+0

我從$權限中刪除offline_access並在facebook應用中設置了「刪除offline_access權限:已啓用」 ,但仍然無法將內容發佈到Facebook未登錄請通知我什麼是我在代碼 –

+0

中所做的所有更改?鏈接? –

+0

是的,我已經提到的鏈接..請問我登錄..可以請你幫我改變代碼 –

相關問題