Facebook登录在应用程序浏览器中的Andriod Facebook中不起作用

问题描述 投票:3回答:1

[从很长的登录时间开始,我就在我的网站上使用Facebook登录Javascript SDK,但最近它停止在Android Facebook应用程序内浏览器中运行。当我单击“登录”按钮时,它将重新加载整个页面以转到授权页面,然后又回来了,什么都没得到

Facebook提供的示例也存在相同问题,甚至使用FB.login功能以及Facebook登录按钮(https://developers.facebook.com/docs/facebook-login/web/login-button)进行了测试。他们两个都得到了相同的结果。它只是刷新页面。

示例代码:

<script>

function LoggedFb(){
      FB.login(function (response) {
                FB.api(`/me?fields=id,email&access_token=${response.authResponse.accessToken}`, function 
                (userResponse) {
                    alert(userResponse.email);
                });
            }, { scope: 'email' })
}

</script>

该代码在除Android Facebook应用程序内浏览器以外的所有平台上均有效。

谢谢。

javascript facebook facebook-javascript-sdk facebook-login facebook-browser
1个回答
0
投票

对我来说,这是一个恒定的循环:登录,刷新并重试而从未登录。

我能够使用FB.getLoginStatus而不是仅使用FB.login来解决此问题。

如果用户已经通过fb登录,它将通过。如果没有,将进行一次刷新,但是登录将起作用。

如果有人可以解决这个问题,我将不胜感激,因此根本不会刷新。

示例代码:

function signIn() {
  FB.getLoginStatus((response: any) => {
    if (response.status !== 'connected') {
      return FB.login((response: any) => {
        handleFbResponse(response);
      }, {
        scope: 'public_profile,email',
        enable_profile_selector: true,
        auth_type: 'rerequest',
        return_scopes: true
      });
    } else {
      handleFbResponse(response);
    }
  });
}

function handleFbResponse(response) { ... }
© www.soinside.com 2019 - 2024. All rights reserved.