I am using Facebook js to allow user's to login. THe login part on the js works perfectly but I want to catch the signed_request that Facebook sends (with the use of a server-side language such as php or java). Reading their documentation (https://developers.facebook.com/docs/facebook-login/using-login-with-games/) on how to catch signed_requests was not very informative. They state "The signed request is sent via an HTTP POST to the URL set as your Canvas URL", so I went to my exact url (mywebsitenamehere.com/login.php which I stated as my Canvas URL and added code to catch the POST['signed_request'] (I assume this is it, as I can't find anywhere on Facebook which tells you the name of the variable). The problem is nothing happens, I added some code in the login.php page to simply redirect to another website if the POST variable was set for testing purposes, and nothing happens. I would really appreciate a concrete example of what I am supposed to do. Searching the internet I was able to find some examples, but it was people who were using php for their login, but I am using JS.
1 Answers
It´s in the text of the link you posted:
"When you run a game on Facebook.com, you can access a signed request parameter"
So, the signed_request is only available in Canvas Apps through their Canvas URL on Facebook: https://apps.facebook.com/appnamespace
...or in Page Apps, of course. Your put in your own server URL corretly, but you also need to set an app namespace and your own server URL will be loaded in an iframe at apps.facebook.com/appnamespace.
That being said, you can use the PHP SDK to get the data out of it ($facebook->getSignedRequest()), or the function presented in your link (parse_signed_request).
edit: You cannot access the signed_request directly in JavaScript, but you could just echo it with your server language. For example (not tested, but you will get the idea):
<script>
var signed_request = '<?php echo json_encode($signed_request); ?>';
</script>