"<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。
请参阅图片中指定的网站网址?这是登录到FB并接受应用程序时页面被重定向到的URL吗?
答案 0 :(得分: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';
});
答案 1 :(得分:0)
正确的语法是data-scope="email"
,而不是scope="email"
。