即使已经获得授权,授权窗口也会重新打开然后快速关闭。如何避免这种情况?

发布于 2024-12-09 12:40:28 字数 1393 浏览 0 评论 0原文

我在 Facebook 上的应用程序使用 JavaScript SDK。当用户导航到我的应用程序页面并转到我的应用程序时,会弹出一个窗口,要求他们授权该应用程序。这效果很好。

但是,如果他们授权该应用程序,然后稍后返回该应用程序,另一个弹出窗口(我认为是另一个授权窗口)将快速打开然后关闭。

我的代码是做什么的?代码如下。

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '221953271200525', // App ID
      channelURL : '//www.vidjahgames.com/fall/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here


FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');

     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});


  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

My App on Facebook uses the JavaScript SDK. When a user navigates to my app page and goes to my app, a popup asks them to authorize the app. This works well.

However, if they authorize the app, then return to it later, another pop-up (which i believe to be another authorization window) will quickly open then close.

What is my code is doing this? Code is below.

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '221953271200525', // App ID
      channelURL : '//www.vidjahgames.com/fall/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here


FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');

     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});


  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

FB.login 使弹出窗口出现,因此您应该首先知道用户是否已登录,如果没有则使登录弹出窗口出现:

FB.getLoginStatus(function(response) {
  if (response.session) {
   // A user has logged in, and a new cookie has been saved
   FB.api('/me', function(response) {
        _userName = response.name;
        alert("hello"+_userName);
     }.bind(this));
 } else {
   FB.login(function(response) {
      // the rest of your code here...
   }

 }
});

FB.login makes the popup appear, so you should first know if the user is logged in and if not make the login popup appear:

FB.getLoginStatus(function(response) {
  if (response.session) {
   // A user has logged in, and a new cookie has been saved
   FB.api('/me', function(response) {
        _userName = response.name;
        alert("hello"+_userName);
     }.bind(this));
 } else {
   FB.login(function(response) {
      // the rest of your code here...
   }

 }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文