2011-08-10 108 views
2

我已經在php mysql中創建了一個facebook應用程序,現在我想將應用程序的更新傳遞給用戶牆,它不是一個像按鈕,而是我想要在用戶牆上共享的一個活動。很像:如何在用戶牆上張貼

XXX剛吃午飯的比薩餅,通過logUrLunch應用

I HV成功地連接到Facebook,並從Facebook獲得的用戶ID如下:

$facebook = new Facebook(array(
    'appId' => 'xxxxxxxxxxxxx', 
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
)); 

// Get User ID 
$user = $facebook->getUser(); 

if ($user) { 
    try { 
    // Get the user profile data you have permission to view 
    $user_profile = $facebook->api('/me'); 
    $uid = $facebook->getUser(); 
    session_start(); 
    $_SESSION['userID'] = $uid; 

    //print_r($user_profile); 
    //echo "</pre>"; 
    } catch (FacebookApiException $e) { 
    $user = null; 
    } 
} else { 
    die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>'); 
} 

回答

0

下面的代碼一定工作:即使你沒有權限,它會嘗試讓他們

$facebook = new Facebook(array(
    'appId' => 'xxxxxxxxxxxxxxxxxx', 
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
)); 
$user = $facebook->getUser(); 
$user_profile = $facebook->api('/me'); 


if(array_key_exists('publish_stream', $permissions['data'][0])) { 
       // Permission is granted! 
       // Do the related task 
       //$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!')); 
        $post_id = $facebook->api('/me/feed', 'post', $attachment); 

      } else { 
       // We don't have the permission 
       // Alert the user or ask for the permission! 
       echo "Click Below to Enter!"; 
       header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream"))); 
      } 
2

您必須首先被授予publish_streamextended permission

然後你可以用auto_publish參數集了Facebook的Javascript SDK使用stream.Publish方法true或退房手續也可用於實現這一圖形API文檔here的「發佈」部分。