0

我在 Facebook 上创建了一个应用程序,但在我请求权限之前,我想检查用户是否已登录并执行一些任务。

我试过这个:

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


    $user = $facebook->getUser();
    if ($user) {
      echo 'logged in';
    } else {
      echo 'not logged in';
    }

但它总是要求权限。

4

1 回答 1

1

我使用了这段代码:

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    FB.init({
      appId      : 'xxxxxxx', // App ID
      channelUrl : 'YOUR_URL/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });


    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
                    //User Is Logged In and authorized
            var uid = response.authResponse.userID;
        } else if (response.status === 'not_authorized') {
            //User is Logged in and not authorized
        } else {
            // the user isn't logged in to Facebook.
        }
    });
};
</script>
于 2012-08-13T13:11:37.900 回答