Facebook API-在用户登录后运行javascript
现在我有了这个:Facebook API-在用户登录后运行javascript,javascript,facebook,api,Javascript,Facebook,Api,现在我有了这个: <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> window.fbAsyncInit = function() { FB.init({ appId:'188492754501683', cookie:true, status:true, xfbml:t
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({ appId:'188492754501683', cookie:true, status:true, xfbml:true });
};
</script>
<fb:login-button perms="email">
login with Facebook
</fb:login-button>
当我在对FB.init()的调用中添加这个函数时,它在加载窗口后立即运行,这是可以理解的,但不是我想要的
我希望代码在用户单击“使用Facebook登录”按钮后运行,然后成功登录,等等
有人能给我指出正确的方向吗?我搜索过谷歌,但似乎什么也找不到:/
提前谢谢你,Tom。你可以利用这些活动:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Facebook Test</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
// user logedin
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:login-button perms="email">
Login with Facebook
</fb:login-button>
</body>
</html>
Facebook测试
window.fbAsyninit=函数(){
init({appId:'YOUR_APP_ID',status:true,cookie:true,xfbml:true});
FB.Event.subscribe('auth.login',函数(响应){
//用户登录
});
};
(功能(){
var e=document.createElement('script');
e、 类型='text/javascript';
e、 src=document.location.protocol+
“//connect.facebook.net/en_US/all.js”;
e、 异步=真;
document.getElementById('fb-root').appendChild(e);
}());
使用Facebook登录
有关可订阅的更多活动,请参阅
更新了完整的示例Hi,我尝试了这一点,但当我在块中添加对FB.api()的调用时,当页面加载时,它仍然运行。我的完整代码位于:Thank.Thank,我尝试了这种方法,当窗口加载时,它会停止代码运行,但当单击按钮时,它也不会响应(警报窗口不会弹出):S
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Facebook Test</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
// user logedin
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:login-button perms="email">
Login with Facebook
</fb:login-button>
</body>
</html>