2012-02-22 35 views
0

我正在使用Php-sdk上的示例代碼,想知道如何在授權後將用戶重定向到畫布頁,目前它只是發回到php頁面。如何在授權後重定向到畫布頁

<?php 
require 'src/facebook.php'; 

$facebook = new Facebook(array(
    'appId' => 'AppId', 
    'secret' => 'Secret', 
)); 

// See if there is a user from a cookie 
$user = $facebook->getUser(); 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>'; 
    $user = null; 
    } 
} 

?> 

<!DOCTYPE html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <body> 
    <?php if ($user) { 
    echo " authorized"; 
    ?> 
     Your user profile is 
     <pre> 
     <?php print htmlspecialchars(print_r($user_profile, true)); ?> 
     </pre> 
    <?php } else { echo "Not Authorized"; ?> 
     <fb:login-button></fb:login-button> 
    <?php } ?> 
    <div id="fb-root"></div> 
    <script> 
     window.fbAsyncInit = function() { 
     FB.init({ 
      appId: '<?php echo $facebook->getAppID() ?>', 
      cookie: true, 
      xfbml: true, 
      oauth: true 
     }); 
     FB.Event.subscribe('auth.login', function(response) { 
      window.location.reload(); 
     }); 
     FB.Event.subscribe('auth.logout', function(response) { 
      window.location.reload(); 
     }); 
     }; 
     (function() { 
     var e = document.createElement('script'); e.async = true; 
     e.src = document.location.protocol + 
      '//connect.facebook.net/en_US/all.js'; 
     document.getElementById('fb-root').appendChild(e); 
     }()); 
    </script> 
    </body> 
    </html> 

所以簡而言之,如何設置我的重定向URL?

+0

是的,第一個鏈接爲我做了。唯一的問題,最終需要而不是

1

不能看到你所要求的權限,但將用戶重定向到相同的應用程序後安裝我使用此代碼:

$loginUrl = $facebook->getLoginUrl(
      array(
       'scope'   => 'user_about_me', 
       'redirect_uri' => 'FACEBOOKS_FULL_APP_URL' 
      ) 
    ); 
相關問題