[英]FB.ui feed popup blocked after fb.login
Here's code flow, first is the login and it's work good, but after that i want to immediately call feed function, that's probably the reason why browser blocked it, is there any other way how i can do this? 这是代码流,首先是登录并且运行良好,但是在那之后我想立即调用feed函数,这可能是浏览器阻止它的原因,还有其他方法可以做到这一点吗? Its work good if the display is set to iframe, but i really want it as a popup.
如果将显示设置为iframe,则其效果很好,但我真的希望将其作为弹出窗口。 Tahnks.
火车
<a href="#" onclick="fblogin()">Share</a>
function 功能
function fblogin() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', {fields: 'last_name, first_name, gender, email, id'}, function(reslog) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
postToFeed(reslog.gender);
}
});
});
} else {
//console.log('X');
}
}, {scope:'email'});
}
postToFeed postToFeed
function postToFeed(gender) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.ui( {
method: 'feed',
display: 'popup',
[...]
}, function( response ) {
console.log( 'before',response );
if ( response !== null && typeof response.post_id !== 'undefined' ) {
console.log( 'done',response );
}
});
}
});
}
You have to call FB.ui
dialogs directly on user interaction (= in the callback function of a mouse event). 您必须直接在用户交互时调用
FB.ui
对话框(=在鼠标事件的回调函数中)。 FB.getLoginStatus
is asynchronous, that´s why (good) browsers block it. FB.getLoginStatus
是异步的,这就是(好的)浏览器阻止它的原因。
Use FB.getLoginStatus
on page load instead, and store the status. FB.getLoginStatus
在页面加载时使用FB.getLoginStatus
,并存储状态。 Or better: remove it, because you don´t need to authorized a user for the FB.ui
dialogs. 或
FB.ui
是:将其删除,因为您不需要为FB.ui
对话框授权用户。 And in your code it would not make any sense, because you only use it after FB.login
and even after an API call - so the user is surely logged in. 而且在您的代码中这没有任何意义,因为您仅在
FB.login
之后甚至在API调用之后才使用它-因此,用户一定可以登录。
FB.login
is asynchronous too, and trying to present a share dialog to the user immediately after login is not only annoying for the user, it´s also against the rules imho. FB.login
也是异步的,尝试在登录后立即向用户显示共享对话框不仅使用户烦恼,而且违反了恕我直言的规则。 I would count that as "incentivizing": 我认为这是“激励”:
Only incentivize a person to log into your app, enter a promotion on your app's Page, or check-in at a place.
仅鼓励他人登录您的应用,在应用的页面上输入促销信息或在某个地方签到。 Don't incentivize other actions.
不要激励其他行动。
Source: https://developers.facebook.com/policy/ 资料来源: https : //developers.facebook.com/policy/
New code: 新代码:
HTML: HTML:
<a href="#" onclick="postToFeed()">Share</a>
JavaScript function "postToFeed": JavaScript函数“ postToFeed”:
FB.ui( {
method: 'feed',
display: 'popup',
[...]
}, function( response ) {
console.log( 'before',response );
if ( response !== null && typeof response.post_id !== 'undefined' ) {
console.log( 'done',response );
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.