- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直致力于将 Facebook Login
与我的网站集成,到目前为止,我已经取得了大部分成功;但是,我仍然有一些疑问。
在我的主页上;我有一个 a href
按钮,它将触发一个 Javascript 函数,该函数将通过弹出窗口提示用户登录 Facebook;如果是第一次,系统会再次弹出窗口提示用户请求权限!
用户登录(并接受权限)后; (s)他将使用 document.location.href
重定向到另一个页面;到目前为止,一切都很顺利。然而,我接下来想做的是:
我想 - 在加载用户重定向到的页面时 - 显示欢迎消息(欢迎[电子邮件]) - 然后我想根据一些数据库信息动态(动态)生成一些元素附加到用户名。
我正在尝试在 Javascript 中做到这一点:
<script>
$('document').ready(function(){
window.fbAsyncInit = function() {
FB.init({
appId : '[my app id]',
oauth : true,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
$(document).trigger('fbload');
};
$(document).on('fbload', function(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me', function(response) {
user_email = response.email; //get user email
// Here, I can display the welcome message :)
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
});
});
</script>
这段代码工作得很好:) - 但是,如果我从函数中删除FB.getLoginStatus
,这将导致以下代码:
$(document).on('fbload', function(){
FB.api('/me', function(response) {
console.log(response);
user_email = response.email; //get user email
console.log(user_email);
// Here, I can display the welcome message :)
});
我得到以下 user_email
输出:
未定义
我似乎无法理解其中的逻辑!由于 FB.getLoginStatus 只检查用户是否登录;为什么它(或缺少它)会中断函数调用 FB.api
?
如果有人能解释这里实际发生的事情的逻辑,我将不胜感激!
注意:无论如何,我最终可能会使用 FB.getLoginStatus
,但我主要关心正在发生的事情的逻辑!
最佳答案
如果没有 FB.getLoginStatus(function(response) { 提供的事件访问 token ,您的 FB.api('/me', function(response) {) 函数将无法工作 功能。
您可以通过将代码更改为以下内容在浏览器的控制台中看到这一点:
$(document).on('fbload', function(){
FB.getLoginStatus(function(response) {
console.log(response); //CHANGE
FB.api('/me', function(response) {
user_email = response.email; //get user email
console.log(response); //CHANGE
});
});
});
这是因为 FB.api('/me', function(response) { 正在询问有关当前 FB 用户的各种数据(姓名、性别、家乡、教育程度、用户名、引言...... .),因此 Facebook 只是确保您让该用户登录到您的应用程序。
关于javascript - 为什么这里需要FB.getLoginStatus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17385863/
我一直致力于将 Facebook Login 与我的网站集成,到目前为止,我已经取得了大部分成功;但是,我仍然有一些疑问。 在我的主页上;我有一个 a href 按钮,它将触发一个 Javascrip
我的代码的删节版: $('#de-auth_button').click(function(){ FB.api('/me/permissions', 'delete', function (res
FB.getLoginStatus 函数出于某种原因对我不起作用 - 尽管它曾经有一段时间。下面是非常基本的代码,警报从不弹出——看起来 FB.getLoginStatus 从不调用提供的函数。有什么
Facebook 的 Javascript SDK 有一个名为 getLoginStatus 的方法,当页面上的图像请求也停止时(即浏览器没有收到 200 或404 很长一段时间。) 如果您等待了非常
我不熟悉使用 Facebook SDK 开发网站。所以请多多包涵。 下面是我用于验证我是否已登录 Facebook 的简单代码。出于某种原因,我总是收到“not_autherized”响应,即使我是我
我有一个难题。困难意味着我搜索了网络和 StackOverflow 以及整个 FBJS SDK 文档,但没有找到答案。 我正在构建一个 Page Tab 应用程序,我想让粉丝在其中参与 rsvp 事件
标题真的说明了一切。在某些(未确定的)条件下,FB.getLoginStatus() 只是停止工作并且不会调用我给它的回调。我发现的唯一有趣的线索是 FB.Auth._loadState 卡在“正在加
使用有效的 Facebook 应用程序调用 FB.getLoginStatus 时,响应状态始终未知。确切的响应是 {authResponse: undefined, status: "unknown
我有一个 Facebook 页面选项卡应用程序,在刷新页面后才能正确加载。一个多星期以来,我一直在努力解决这个问题,但我已经无计可施了。 代码如下:
还有其他人遇到 FB.getLoginStatus 未返回登录用户 session 的问题吗?我在 Facebook 上创建了一个错误: https://developers.facebook.com
我正在使用 FB.getLoginStatus(根据文档),它在所有桌面浏览器中都按预期工作,但由于我无法推断的原因,调用只是简单地消失在从 iPad 或 Android 调用时,la-la land
我正在尝试编写一个代码来检查用户是否登录,发现FBJS API中有一个内置的方法,叫做getLoginStatus() 我已经在html里面实现了,但是对于某些方法,getLoginStatus()
如果我登录到 facebook.com,我希望对 FB.getLoginStatus 的调用将返回 status='not_authorized'。相反,它返回 status='unknown',即使
我收到常见的 JS 错误“ Uncaught ReferenceError :未定义 FB” 关于同一个问题有很多问题,我已经尝试了每个可用的解决方案 stackoverflow 但无济于事。显然,人
我无法让它工作,我已经尝试了我在网上找到的所有解决方案。有人可以调查一下,让我知道我做错了什么吗? $(document).ready(function(){ window.fbAsync
我目前正在使用 phonegap 在 Android 上开发一个应用程序,并且想在该应用程序中使用 Facebook。我在 Facebook 上创建了一个名为“测试”的应用程序。当我没有登录到“测试”
我们有一段代码: checkStatus: function() { var self = this; FB.getLoginS
我通过按钮单击事件调用 Facebook JS SDK 的 FB.getLoginStatus。我的问题是,如果状态参数设置为 true,则会触发浏览器弹出窗口阻止程序,从而阻止显示登录对话框。但是,
我实现了 facebook 连接并且工作正常。 此函数在登录后返回我的名字。 FB.getLoginStatus(function (response) { if (response && r
目前 FB.getLoginStatus 在 facebook 使用新的 SDK 和 OAuth 2.0 更改后根本没有触发。 我们过去常常在 FB.getLoginStatus 中获取响应并调用我们
我是一名优秀的程序员,十分优秀!