Sending forms in Facebook applications [closed]
Today, my almost finished Facebook application stopped working. I have some sort of a "registration" form in the app for setting the user's in-game nick and similar stuff.
The problem is that upon submitting the form, the Facebook PHP SDK insists that $facebook->getUser()
is NULL
. My code reacts to this by redirecting the user to $facebook->getLoginUrl(array("scope" => ..., etcetera))
. Then, the user is redirected back to my application by Facebook, but, of cours开发者_JAVA百科e, without the data that was posted into the form.
I assume I should probably pass some sort of a hidden element in the form so that the Facebook PHP SDK can do its magic. Could you please tell me how does one use forms in a Facebook app properly?
Okay, so I finally found out that the problem lay in my code - I had a bug in session handling. Sorry for the bashing, Facebook :)
does this work?
$facebook = new Facebook(array(
'appId' => ... ,
'secret' => ... ,
));
$user = $facebook->getUser();
if (!$user) {
$loginUrl = $facebook->getLoginUrl();
// then redirect to the $loginurl
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
<?php
if (!isset($_POST['my_guess'])) {
?>
pick a number between 1 and 10
<form action="index.php" method="post">
<input type="text" name="my_guess">
<input type="submit">
</form>
<?php
} else {
print $facebook->getUser()." you picked ".$_POST['my_guess'];
}
?>
</body>
</html>
精彩评论