1

Facebook接続を使用してログインした後、ユーザーを特定のURLにリダイレクトする必要があります。以下のコードはfireboxで機能しますが、chromeでは機能しません。助けてください

 <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>
4

1 に答える 1

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>");
}

?>

于 2012-05-24T14:04:17.470 に答える