Facebook连接无法使用chrome

时间:2012-05-09 18:55:58

标签: facebook

使用Facebook连接登录后,我需要将用户重定向到特定的URL。以下代码适用于firebox.but不适用于chrome.please帮助我

 <script type="text/JavaScript">
          FB.init({
              appId: '366168323431073', cookie: true,
              status: true, xfbml: true
          });
          FB.Event.subscribe('auth.login', function () {
              window.top.location = "http://www.domain.com";
          });
      </script>

1 个答案:

答案 0 :(得分:0)

更改应用中的重定向uri

<?php

// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');

define('FACEBOOK_APP_ID',"YOUR-APP-ID-HERE");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET-HERE");
define('REDIRECT_URI',"YOUR-REDIRECT-URL-HERE");
$user = null;

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

$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.

if($user == 0) {
    // If the user is not connected to your application, redirect the user to authentication page
    /**
     * Get a Login URL for use with redirects. By default, full page redirect is
     * assumed. If you are using the generated URL with a window.open() call in
     * JavaScript, you can pass in display=popup as part of the $params.
     * 
     * The parameters:
     * - redirect_uri: the url to go to after a successful login
     * - scope: comma separated list of requested extended perms
     */

    $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI));

    echo ("<script> top.location.href='".$login_url."'</script>");

} else {
    // if the user is already connected, then redirect them to landing page or show some content
    echo ("<script> window.location.href='".REDIRECT_URI."'</script>");
}

&GT;