我写了这段代码。登录facebook后,文档需要重定向到check3.php。这是代码..
<html>
<body>
<div id="header">
<h1><a href="index.php">ReviewBox</a></h
<ul id="nav">
<li><a href="#">Real Reviews For Real People</a></li>
<li style="background: url(images/request.png);display:block; margin : 0 10px 0 0;float:right;text-indent: -9999px; width : 200px; height: 30px;"><a href="request.php">Request Review From Friends</a></li><br/>
</ul><br/><br/><br/><br/></div>
<div id="container">
<div id="content">
<p>Someone is always out there, waiting to know what you have to say.
So why not speak out with ReviewBox?</p><br/>
<h6>Get Started!</h6><br/><br/>
<center>
<div id="fb-root"></div>
<script language="javascript" src="json2.js"> </script>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'xxxxxxxxxxxx', cookie:true,
status:true, xfbml:true
});
</script>
<fb:login-button perms="read_stream,publish_stream,email,offline_access">
Login with Facebook
</fb:login-button>
<br/><br/>
<p>Like ReviewBox :</p><br/><center>
<fb:like href="https://www.facebook.com/apps/application.php?id=xxxxxxxxxx" send="false" width="220" show_faces="true" font=""></fb:like></center>
<script>
FB.api('/me',function(response) {
setCookie("fbname",response.name,365);
setCookie("fbid",response.id,365);
setCookie("checker",1,1);
var username=getCookie("fbid");
if (username!="undefined" && username!="")
{
alert("Welcome Again, " + response.name + "!");
sample();
//window.location.reload();
}
else
{
alert("Welcome Guest! Please Login with Facebook To Get Started With ReviewBox!");
username=response.id;
username2=response.name;
if (username!=null && username!="")
{
setCookie("fbid",username,365);
setCookie("fbname",username2,365);
setCookie("checker",1,1);
}
}
});
function sample()
{
document.form1.submit();
}
</script>
<form name="form1" action="check3.php" method="post">
<input type="hidden" name="fb_user" id="fb_user" value="" />
</form>
</body>
</html>
但是当我运行这段代码并登录到facebook后,sample()函数中的代码没有被执行..因此我的页面不会重定向到check3.php。 有什么建议吗?
答案 0 :(得分:0)
了解,
首先,确定Facebook响应对象是否实际包含值。 API可能是出于某种原因,而不是返回ID结果?
一旦确认API确实返回了一个值,也许在“if”语句中使用它而不是用户名?
我不知道到底出了什么问题,但我相当确定“fbid”值没有在cookie中设置,这对我来说意味着API没有返回正确的结果,或者你正在传递在API的无效参数中。
祝你好运!ħ