问题
FB.Event.subscribe('auth.login', function(response) {
FB.api('/me', function(response){
//Some operation
});});
Above piece of JavaScript code runs when user logs-in through Facebook
or
when user is already logged-in the browser and you open the page containing the above JavaScript.
Is there any way to execute the operation only when user logs-in for first time and escape the operation when user is already logged-in in the browser?
回答1:
Run FB.getLoginStatus to see if the user is already connected to your app and logged in. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
} else {
// no user session available, someone you dont know
}
});
回答2:
Try subscribing to the event if and only if the user is not connected.
function listen_for_authorization (cb) {
FB.getLoginStatus(function (res) {
if (!res || res.status !== "connected") {
FB.Event.subscribe('auth.login', cb);
}
}
}
We reproduced this in Safari/Mac, Firefox/Windows, Internet Explorer.
See http://developers.facebook.com/bugs/255767001140894
来源:https://stackoverflow.com/questions/6733348/fb-event-subscribeauth-login-functionresponse-issue