Facebook javascript事件没有被解雇我转向它
我在我的网站上使用Facebook JavaScript SDK,有一个选项可以在用户登录/注销Facebook时设置事件,这样我就可以在我的网站上显示他的通知。
无法管理它,尝试所有内容,也使用 offline_access 权限。
I am using Facebook JavaScript SDK with my site, there is an option there to set events when user login/logout from Facebook so i can show him notifications in my website. can't manage it to work, tried everything, also using offline_access permission.
这里是我的HTML代码:
here is my html code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="blabla" />
<meta name="keywords" content="blabla" />
<meta property="og:title" content="blabla" />
<meta property="og:url" content="http://XXX/" />
<meta property="fb:app_id" content="XXX" />
<title>Facebook Notifier</title>
<link href="<?php echo base_url(); ?>styles/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.cookie.js"></script>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/global.js"></script>
</head>
<body>
<div id="fb-root"></div>
<div id="my_div">
</div>
</a>
</body></html>
这是我的js代码:
FB.init({
appId : 'XXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true, // enables OAuth 2.0
channelUrl : 'http://XXX/channelUrl'
});
FB.getLoginStatus(function(response) {
if (response.authResponse) {
connected = true;
}
else{
connected = false;
}
}, true);
FB.Event.subscribe('auth.authResponseChange', function(response) {
if(response.authResponse) connected = true;
else connected = false;
});
在这个js代码的末尾我有一个每几秒运行一次检查连接变量的函数,它是一个全球性的。它没有改变我试图从Facebook登录/注销,没有事件发生。
仅当我刷新页面时我才能获得用户状态。在firefox firebug控制台
我收到消息(也在chrome中试过,即):
未捕获异常:错误: https://www.facebook.com Proxy.InstallTrigger
i尝试通过在谷歌和stackoverflow中找到关于此错误的所有内容来解决它,但仍然没有工作。
btw:当我在原始文件中写XXX时,我的网址或我的appid。
谢谢。
in the end of this js code i have a function that run every few seconds checking the connection variable, its a global one. and it not changed i tried to login/logout from facebook and no event fires. only when i refresh the page i can get the user status. in firefox firebug console i get the message (also tried in chrome, ie): uncaught exception: Error: https://www.facebook.com Proxy.InstallTrigger i tried to solve it by doing everything i can find about this error in google and also in stackoverflow and still not working. btw: when i wrote XXX in the original files its my url or my appid. thanks.
我一直对 auth持怀疑态度。
Facebook在你的情况下触发事件我可能只是自己设置一个轮询器来检查连接用户的身份验证状态。像这样:
I've always been a bit skeptical about the auth.
events the Facebook fires so in your case I'd prob just setup a poller myself to check the auth status of the connected users. Like this:
var connected;
FB.init({
appId : 'XXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true, // enables OAuth 2.0
channelUrl : 'http://XXX/channelUrl'
});
FB.getLoginStatus(handleUserStateChange);
FB.Event.subscribe('auth.authResponseChange', handleUserStateChange);
function handleUserStateChange(response) {
connected = !!response.authResponse;
}
setInterval(function() {
FB.getLoginStatus(handleUserStateChange, true);
}, 10000) // poll every 10 seconds
此外,您在 status:true $ c> FB.init 配置对象,您不需要在开始时将第二个参数传递给 FB.getLoginStatus
,因为这会强制检查到Facebook而不是从存储的变量中读取(这已经是我们刚刚创建的最新信息)。
Also as you defined status: true
in the FB.init
config object you don't need to pass the second parameter to FB.getLoginStatus
at the start as that forces a check to Facebook instead of reading from the stored variable (which is already the latest information as we just initd).