【发布时间】:2022-01-31 15:25:46
【问题描述】:
我在我的网站上使用 Facebook JavaScript SDK,有一个选项可以在用户从 Facebook 登录/注销时设置事件,这样我就可以在我的网站上向他显示通知。 无法使其正常工作,尝试了所有方法,还使用了 offline_access 权限。
这是我的 html 代码:
<!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 我试图通过尽我所能在谷歌和stackoverflow中找到关于这个错误的一切来解决它,但仍然无法正常工作。 顺便说一句:当我在原始文件中写 XXX 时,它是我的 url 或我的 appid。 谢谢。
【问题讨论】:
标签: javascript facebook