2011-02-25 86 views
0

我已經編寫了以下腳本,用於檢查用戶的會話並相應地顯示登錄/註銷鏈接。腳本的作品,但問題是,我不知道如何設置回調URL,沒有字段(或至少我找不到一個)在我的FB應用程序設置頁面。有任何想法嗎?Facebook PHP SDK,如何定義回調URL

$facebook = new Facebook(array(
    'appId' => 'xxx', 
    'secret' => 'xxx', 
    'cookie' => true, 
)); 

$session = $facebook->getSession(); 

$me = null; 

if ($session) { 
    try { 
    $uid = $facebook->getUser(); 
    $me = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    } 
} 

?> 
<?php if ($me): ?> 
    <a href="<?php echo $facebook->getLogoutUrl(); ?>">Logout</a> 
<?php else: ?> 
    <a href="<?php echo $facebook->getLoginUrl(array('req_perms'=>"email,publish_stream")); ?>">Login</a> 
<?php endif; ?> 

回答

3

該參數被稱爲「下一個」。所以,你不喜歡這樣寫道:

<a href="<?php echo $facebook->getLoginUrl(array('req_perms'=>"email,publish_stream",'next'=>"welcome.html")); ?>">Login</a> 

更改「welcome.html」無論你希望用戶在登錄後登陸你的服務器上

+0

在最新的SDK'redirect_uri'代替'next'。 https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ – Shahid

-1

在Facebook的PHP SDK文件,關於線418

public function getLoginUrl($params=array()) { 
    $currentUrl = $this->getCurrentUrl(); 
    return $this->getUrl(
     'www', 
     'login.php', 
     array_merge(array(
     'api_key'   => $this->getAppId(), 
     'cancel_url'  => $currentUrl, 
     'display'   => 'page', 
     'fbconnect'  => 1, 
     'next'   => $currentUrl, 
     'return_session' => 1, 
     'session_version' => 3, 
     'v'    => '1.0', 
    ), $params) 
    ); 
    } 

和445

public function getLogoutUrl($params=array()) { 
    return $this->getUrl(
     'www', 
     'logout.php', 
     array_merge(array(
     'next'   => 'http://yoururl.com/?logout=1', // or $currentUrl the same page who make the callback , and destroy session if it. 
     'access_token' => $this->getAccessToken(), 
    ), $params) 
    ); 
    } 
+0

那麼在這些代碼中'$ params = array()'和'array_merge'的目的是什麼? – ianace