Facebook Javascript SDK - Fb.login在Facebook内置浏览器中无法使用。

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

我注意到Facebook的FB.Login功能或Facebook登录按钮在Android上使用Facebook的应用浏览器打开的页面上不再工作。(当用户点击Facebook应用内的URL,并在应用内置浏览器上打开)。在Messenger上,它可以正常工作。

我不知道这个错误是什么时候开始的。我甚至使用FB.login功能和Facebook登录按钮进行了测试( https:/developers.facebook.comdocsfacebook-loginweblogin-button。 ). 得到的结果都是一样的。它只是刷新了页面。

示例代码。

<script>

function LoggedFb(){
       //This is just a sample code. This code when executed from a URL opened from Facebook's Browser ( When user clicks on a url on the Facebook App ), won't run. From Chrome or other browser works fine.
    alert("got in here");
}

</script>

<div class="fb-login-button" data-width="" data-size="large" data-button-type="continue_with" data-auto-logout-link="false" data-onlogin="LoggedFb" data-use-continue-as="false" data-scope=""></div>

</html>

上面的例子,在Chrome浏览器上运行时,会正常工作并调用LoggedFb函数。当在Facebook内置的浏览器上运行带有这段代码的页面时,它只会刷新。

我也试过实现FB.Login函数,但也不行。

我甚至填写了一个bug报告( https:/developers.facebook.comsupportbugs456215991739392。)但他们说这不是一个错误。

自从这个开始,我看到很多网站的登录按钮坏了。有谁遇到过这种情况,或者有解决办法吗?

谢谢。

facebook facebook-javascript-sdk
1个回答
1
投票

每当访问来自Facebook移动浏览器时。点击FB.login没有任何作用,因为它已经假定你已经登录了。你需要做的是使用当前登录账户的accessToken和userID,使用FB的API获取你需要的细节。

下面是一个Javascript的代码示例。

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

handleResponse(response) {
FB.api(`/me?fields=email,picture,first_name,last_name`,
  (response: any) => {
    this._loginService.socialLogin({
      email: response.email ? response.email : '',
      profilePicture: {
        'url': response.picture.data.url,
        'key': ''
      },
      fullName: `${response.firstName} ${response.lastName}`,
      socialId: response.id,
      ...FACEBOOK_LOGIN
    }).
      subscribe(res => {
      })
  })
}
© www.soinside.com 2019 - 2024. All rights reserved.