facebook - Facebook Javascript SDK - Fb.login 在浏览器内置的 Facebook 上不起作用
问题描述
我注意到 Facebook FB.Login 功能或 Facebook 登录按钮不再适用于在 Android 上使用 Facebook 的应用内浏览器打开的页面。(当用户单击 Facebook 应用程序内的 URL 时,它会在内置浏览器的应用程序上打开)。在 Messenger 上它工作正常。
不知道这个bug是从什么时候开始的。我甚至使用 FB.login 功能以及 Facebook 登录按钮(https://developers.facebook.com/docs/facebook-login/web/login-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 功能,但它也不起作用。
我什至填写了错误报告(https://developers.facebook.com/support/bugs/456215991739392/),但他们说这不是错误。
从这开始,我看到很多网站的登录按钮都损坏了。其他人遇到这种情况,或者有解决方案吗?
谢谢。
解决方案
每当访问来自 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 => {
})
})
}
推荐阅读
- xml - 如何将本地 xml 文件导入我的 vue 组件
- java - Tomcat Webapp 响应给出 ????? 对于特殊字符,例如 'é' UTF-8 编码字符串。每次 Tomcat 按预期重新启动后
- python - Pandas:读取数据框的视图
- asp.net-core-mvc - Loadster 捕获规则未找到变量 __RequestVerificationToken 的匹配项
- python - 在 Python Quart 中获取同步代码的结果
- git - 如何在 Azure DevOps 环境分支控制中允许标记
- sql - 合并 R 中的表并更新日期重叠的行
- vue.js - VSCode中生成Vuex Getter Setter的一种方法
- python - 在多对多关系上使用 django MultipleChoiceField 上的初始值
- android - 使用 ItemTouchHelper 拖动项目时 RecyclerView 滚动到顶部