FB登录按钮不提示第一次用户的范围
问题描述:
"<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登录按钮不提示第一次用户的范围
看到在知情同意指定网站的网址?是登录到FB并接受应用程序后页面被重定向到的URL吗?
答
当用户未在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';
});
答
正确的语法实现这一点是data-scope="email"
,不scope="email"
。
谢谢。但是,在fb_redirect文件中......会话已启动,或者如果它是首次执行插入查询的用户。这些都需要在登录按钮所在的页面上发生吗? – Lance 2013-03-22 22:12:34
你能解释一下自己吗? – 2013-03-22 22:17:59
我现在连接到的互联网不会让我通过ftp连接到我的远程服务器。所以,我无法上传你的代码,看看它是否有效。但是,从以前的经验来看,window.location ='some_other_file.php'从来没有用过。出于某种原因,尽管window.reload()似乎工作得很好。 – Lance 2013-03-22 22:22:30