0
"<div id='fb-root'></div>
<script>
    window.fbAsyncInit = function() 
    {
        FB.init({
            appId: 'ID', 
            status: true, 
            cookie: true, 
            xfbml: true  
        });

        FB.getLoginStatus(function(response) 
        {
              if(response.status === 'connected') 
                {
                    if (response.authResponse != 'undefined') 
                    {
                        window.location = '/fb_redirect.php';
                    }
                } else if(response.status === 'not_authorized')
                {

                } else 
                {
                    FB.Event.subscribe('auth.login', function(response) 
                    {
                        window.location = '/fb_redirect.php';
                    });
                }
            });
        };

        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = '//connect.facebook.net/en_US/all.js#xfbml=1&appId=ID';
            fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));
    </script>

<div class='fb-login-button' data-show-faces='false' scope='email' registration-url='http://www.sportannica.com/fb_redirect.php' size='large' data-width='200' data-max-rows='1'></div>

这就是我现在正在使用的。对于已经接受该应用程序的用户,它可以正常工作。但是,对于初次使用的用户,在单击登录按钮时,不会弹出任何屏幕并显示有关应用程序的详细信息,例如有多少人使用它或它请求的权限类型。它直接指向/fb_redirect.php。

在此处输入图像描述

看到图片中指定的站点 URL 了吗?这是在登录 FB 并接受应用程序时页面被重定向到的 URL 吗?

4

2 回答 2

0

正确的语法是data-scope="email",不是scope="email"

于 2013-05-14T02:10:05.773 回答
0

当用户未在 facebook 上登录时使用登录按钮,如果用户已登录但未授予您的应用程序的权限,您应该使用 oauth 对话框。

你可以通过这样做来实现

FB.getLoginStatus(function(response) {
    if(response.status === 'connected'){
        if (response.authResponse != 'undefined')
            window.location = '/fb_redirect.php';
    }else if(response.status === 'not_authorized'){
    //it means we have a user but he hasn't granted any permissions to our app
    //we're going to redirect him to the permission page
    window.location = 'https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&response_type=code&redirect_uri=YOUR_APP_URL&scope=email';
    } else {
    //the user is not logged in, as you already have a login button you don't have to do nothing  
    }
});

//this should be outside the FB.getLoginStatus function
FB.Event.subscribe('auth.login', function(response) {
    window.location = '/fb_redirect.php';
});
于 2013-03-22T19:02:07.983 回答