添加一个POST参数到fb:login按钮
Add a POST parameter to fb:login button
你好,我试图设置一个POST当用户点击login with facebook按钮。这是因为在我所做的代码中,如果你注销了,但在facebook上登录,那么你会自动再次登录网站…所以如果你点击注销,你永远不会注销。
为了避免这种情况,我尝试设置一个POST,设置一个经典的条件
if ( isset ($_POST['fbconnect']))
我只需要添加一个隐藏的输入和发送表单使用:login-button
这是我试过的…不走运。
<form name="fbconnect" method="post">
<input type="hidden" name="fbconnect" value="fbconnect" />
<div id="fb-root"></div>
<fb:login-button scope='email,user_birthday'></fb:login-button></form>
<?php
}
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?=YOUR_APP_ID?>,
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
// ------------------------------------------------------
// This is the callback if everything is ok
$(this).parents('form').submit();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
我也试着用form的名字替换$(this).parents('form').submit();
form,但它也不起作用
我也试过这个
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?=YOUR_APP_ID?>,
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
// ------------------------------------------------------
// This is the callback if everything is ok
var url = "index.php";
var params = "fbconnect=fbconnect";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
更好的做法是在用户注销时使用重定向,而不是POST,即:
HTML:<a onclick="FB.logout">Logout</a>
和Javascript:
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status == "connected") {
// log in login
}
else if (response.status != "connected") {
// logout logic, i.e
// location.href = "/sessions/logout";
alert("User has disconnected")
location.href = "/index.php?fbconnect=fbconnect"
}
});
如果你坚持要写一篇文章,你可以使用jQuery简单地做一些事情:
FB.Event.subscribe('auth.login', function(response) {
$.post("index.php", {fbconnect: fbconnect}, function(data, response) {
alert(data);
});
});
相关文章:
- FB.login访问令牌facebook javascript SDK
- FB.login Invalid redirect_uri (xd_proxy.php)
- FB.login有效,但弹出窗口不起作用;t关闭
- FB.login总是问我的密码(即使我已经登录)
- fb.login 响应始终返回 true
- fb.login 在后台运行对话框
- 将 Facebook fb:login-button 转换为 SDK JavaScript login
- 页面选项卡应用程序中的FB.ui({method:“oauth”})与FB.login()
- IE FB.login回调未运行,XD代理窗口保持打开状态
- 使用fb.login时,googlechromeauthbox会跳转
- 如何判断用户是否使用FB.login授予您权限
- Facebook注销/断开连接FB.login()在用户已经连接时调用
- Facebook FB.login()弹出窗口获胜't在IE8中关闭
- 添加一个POST参数到fb:login按钮
- About FB.Event.subscribe and FB.login
- 在FB.int()之前调用了facebook登录错误FB.login()
- 无法授权应用程序:FB.login()上的ie错误
- 我如何使用访问令牌来规避FB.login()
- 官方Facebook iOS应用程序在从web应用程序调用FB.login()时总是崩溃
- 如何使fb:login-button作为纯文本