2012-12-19 40 views
1

我從this post得到了有關如何在有人訪問尚未授權該應用程序的畫布頁面時重定向到Facebook授權頁面的幫助。Facebook應用程序授權後重定向到畫布網址而不是畫布頁面

現在,我期待用戶授權後,FB將重定向到畫布頁面(https://app.facebook.com/myapp)。但它重定向到畫布網址(https://myhostingapp.com/game.php?..。)

這是預期的還是我們可以做的任何事情來控制它。如何讓API在授權後重定向到畫布頁?

現在我可以考慮使用$ _SERVER [HTTP_REFERER]來查看我是否來自授權頁面,如果是,則將頁面重新導向​​到畫布頁面。但我希望有可能是做

帆布URL代碼的更好的方法:

if (Config::$fbAvailalbe){ //see below how this variable is derived 
    echo "fb is available"; 
    $facebook = new Facebook(array(
     'appId' => Config::$appId, 
     'secret' => Config::$appSecret, 
    )); 

    $user = $facebook->getUser(); 

    if ($user) { 
     echo "app installed"; 
     try { 
     // Proceed knowing you have a logged in user who's authenticated. 
     $profile = $facebook->api('/me'); 
     } catch (FacebookApiException $e) { 
     error_log($e); 
     $user = null; 
     } 
    } 

    if (!$user) { 
     echo " app not installed gonna redirect"; 
     $scope = "scope=email,read_stream,read_friendlists,publish_stream"; 
     $redirect = $facebook->getLoginUrl(
        array(
         'canvas' => 1, 
         'fbconnect' => 0, 
         'req_perms' => $scope 
         ) 
        ); 
     echo '<script>top.location="' . $redirect . '";</script>'; 
     exit(); 
     //header("Location: $redirect".$scope); 
    } 

    if ($profile){ 
     $firstName = $profile['first_name']; 
     $sid = $profile['id']; 
     var_dump($profile); 
    }else{ 
     echo "unable to get profile"; 
    } 

}else{ 

    echo "fb unavailable, using dmmy"; 
    $firstName = "Dummy Name"; 
    $sid = Config::$testsid; 

} 

Snipet從config.php文件

//this is to derive the $fbAvailable variable 
    //we get this condition satisfied when we run the page runs from fb canvas 
    if (isset($_SERVER['HTTP_REFERER'])){ 

     if (substr_count($_SERVER['HTTP_REFERER'],'apps.facebook.com')){ 
      self::$fbAvailalbe = 1; 
     } 
    } 

回答

0

檢查文檔here。在代碼

兩個錯誤

錯誤#1:

$scope = "scope = email,read_stream,read_friendlists,publish_stream"; 

錯誤#2:

作爲每文檔here(如在現在)

req_params是'scope'

不知道的「畫布」和其可能潛在地忽略「fbconnect」參數,因爲它們不支持任何更

$redirect = $facebook->getLoginUrl(
        array(
         'scope' => $scope, 
         'redirect_uri' => 'https://app.facebook.com/myapp' 
         ) 
        ); 
+0

現在我正在「發生錯誤。 「是否與過時的參數有關?https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/沒有」canvas「和」fbconnect「參數 –

+1

oops看起來像' req_perms'現在只是'範圍'? –

+0

我現在已經計算出確切的錯誤,並在你的答案中編輯了代碼。一旦你接受我的編輯,我會接受這個:) –

相關問題