我正在开发一个与 Facebook 集成的 Facebook 应用程序,并试图获取用户的 FB session 。据我了解,一个常见的使用场景如下。
- 调用
FB.init()
- 调用
FB.getLoginStatus
给它适当的回调。
我运行了以下代码(应用程序 ID)。
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
<!--
function init(){
FB.init({
appId : '9999999999999',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://127.0.0.1:8888/channel.html', // custom channel
oauth : true // enable OAuth
});
alert('going to call FB.getLoginStatus ');
FB.getLoginStatus(function(response) {
alert('whoo hoo!!! getLoginStatus called the callback');
});
}
init();
//-->
</script>
如果用户已经在同一个浏览器 session 中登录到 Facebook,那么一切都会按预期工作 - 返回填充的 _response.authResponse_
。但是,如果用户未登录 Facebook,则根本不会触发回调。检查浏览器网络日志,我看到 Facebook 返回以下响应(来自 http://www.facebook.com/dialog/oauth
的请求?)。
Application Error: There was a problem getting data for the application you requested. The application may not be valid, or there may be a temporary glitch. Please try again later.
我在 Chrome 和 Firefox (Mac) 上检查过这个。
更新
我要感谢所有回复的人。
Ben的评论有答案。
谢谢 Ben - 你让我避免了很多挫折。
最佳答案
原因是最近的bug这只影响沙盒模式。我关闭了沙盒模式,它非常有效。
关于javascript - 如果用户未登录 Facebook,则 FB.getLoginStatus 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7230324/