FB.Event.subscribe('auth.login', function(response) { }) issue

做~自己de王妃 提交于 2019-12-23 17:27:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!